oracle / graaljs

GraalJS – A high-performance, ECMAScript compliant, and embeddable JavaScript runtime for Java
https://www.graalvm.org/javascript/
Universal Permissive License v1.0
1.81k stars 190 forks source link

ES Modules support for built-in `require` #249

Open eleinadani opened 4 years ago

eleinadani commented 4 years ago

Add support for loading Node's ES modules through the experimental require built-in function.

https://nodejs.org/api/esm.html#esm_package_json_type_field https://github.com/graalvm/graaljs/blob/master/docs/user/NodeJSVSJavaScriptContext.md#commonjs-modules-cjs

eleinadani commented 4 years ago

Initial support for ES modules landed in this commit. Given that the Node.js API is still experimental, not all features are implemented. In particular, we don't support (yet) the "exports" field in package.json. However, we already support the "type":"module" option in package.json, so we should be able to load basic npm modules already. @pmlopes feedback is welcome!

pmlopes commented 4 years ago

Are there any night builds? Or in order to test I need to build the whole graalvm myself?

ansalond commented 4 years ago

Hi @pmlopes. We have nightly builds, but the GraalVM import of Graal.js is not yet updated. I can ping you when we have a nightly GraalVM build with these changes.

In the meanwhile, if you need just Graal.js + Graal compiler on JDK11, you can:

The last step prints the path to the newly built GraalVM.