Archi Forum

Archi Plug-ins => jArchi => Topic started by: rchevallier on November 04, 2022, 12:43:30 PM

Title: Ecmascript module support in jArchi ?
Post by: rchevallier on November 04, 2022, 12:43:30 PM
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.
Title: Re: Ecmascript module support in jArchi ?
Post by: Phil Beauvoir on November 04, 2022, 13:47:23 PM
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.

See https://www.graalvm.org/22.2/reference-manual/js/Modules/
Title: Re: Ecmascript module support in jArchi ?
Post by: rchevallier on November 07, 2022, 09:41:57 AM
Hi Phil,
Sorry, I'm not clear with your answers



Title: Re: Ecmascript module support in jArchi ?
Post by: Phil Beauvoir on November 07, 2022, 09:46:12 AM
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.