I am trying to create a native image from a simple node.js example.js
application.
When running the application with:
node --native -i --native example.js
then the application is starting and working as expected.
Now I would like to create a native image. I tried the following command:
native-image --language:js example.js
however it is not working, because of the error:
Build on Server(pid: 77626, port: 64052)
[example.js:77626] classlist: 3,964.04 ms
error: Main entry point class 'example.js' not found.
Error: Processing image build request failed
As a resolution I created a main entry point in example.js
such as:
function main(args) {
console.log("Main app started")
}
however this doesn't work.
Is there a way usually native images are create for js/node.js applications?
No. Currently, as of Dec 2018, creating GraalVM native images for node.js applications is not possible. The native image utility takes Java bytecode and compiles it ahead of time. GraalVM JavaScript engine is a Java program and can be compiled as a native image. This is what you actually run when you execute $GRAALVM_HOME/bin/js
. It still loads JavaScript at runtime, interprets it and compiles it just-in-time to machine code.
GraalVM's node implementation is a normal node
, a native application, with the JavaScript engine replaced by the GraalVM's one.
The GraalVM team is experimenting with possible ways to save precompiled parts of the JavaScript programs, maybe a standard library, or parts of your application, but when this can become available and in which form is unclear.