Ecmascript module support in jArchi ?

Started by rchevallier, November 04, 2022, 12:43:30 PM

Previous topic - Next topic


Hi Phil, JB

according to the GraalVM documentation (22.3 for jArchi 1.3)
it supports ECMA script modules. Clauses

However it doesn't seem to work in jArchi:

org.graalvm.polyglot.PolyglotException: SyntaxError: test3.ajs:2:0 Expected an operand but found import
import {elem} from 'test4.js';
test3.ajs:2:20 Expected ; but found test4.js
import {elem} from 'test4.js';

Any reason why it shoudln't work? Using standard instead of specific "load(...)" shall be useful for library compatibility.

Phil Beauvoir

I got it to work by ensuring that both files (the file with export statements and the one with the import statement) have the file extension ".mjs". For testing I also had to change jArchi to support running ".mjs" files.

So it's possible but having to have the file extension ".mjs" on the runnable file is not nice.

If you value and use Archi please consider making a donation. :-)


Hi Phil,
Sorry, I'm not clear with your answers

  • a script file with extension .mjs cannot be run in Archi, and in a .ajs the import statement is not recognized.
    Is it for a future release?
  • according to the GraalVM documentation, the extension .mjs is not required for the import (in
    QuoteWhen loading modules via a polyglot Source, you can use the inofficial application/javascript+module mime type to specify you are loading a module. When loading with JavaScript code from a file, make sure the module is loaded from a file with the .mjs extension. Loading with the import keyword is not limited by that, and can import from a file of any extension.
    A bug in the documentation ? (Although renaming an imported module file wih a .mjs extension instead of .js is not a real issue)

Phil Beauvoir

That's the way it is with jArchi's implementation of GraalVM. Both files have to have the .mjs extension. I tried all other combinations. We are not using a "poylglot Source" object. I made a test build of jArchi so that .mjs can be run.

Edit: actually the file with the export can have either extension .js or .mjs. However, the file being run, with the import statements, has to have the extension .mjs.
If you value and use Archi please consider making a donation. :-)