Question about graal.js import resolution in polygot context [was Re: Graal embed documentation not in place]

Andreas Woess andreas.woess at oracle.com
Tue Aug 8 13:21:39 UTC 2017


Hi Jerven,

thanks for your interest in Graal.js/GraalVM and giving it a try. We 
appreciate your feedback.

Regarding your first question, our support for ES modules is still 
experimental; partly because the details of how modules are to be loaded 
aren't specified/standardized yet.
A particular problem is that we need to know if a source ought to be 
parsed as Module or Script. Currently, we have a hack in place that if 
the name of the Source starts with "module:" it is treated as a module; 
it also only works with file-based sources right now (as the file path 
is used to resolve imported modules). This will certainly improve in 
future releases.

So, something like this may work:
>         Context context = Context.create("js");
>         context.eval(Source.newBuilder("js", new 
> File("x.js")).name("module:x.js").content("import {x} from 
> 'y.js'").build());

- andreas

On 08/08/2017 11:14, Jerven Tjalling Bolleman wrote:
> Dear Graal devs,
>
> I am really pleased with how smooth this experiment is going. Those 
> snippets already helped a lot.
>
> My first question is how are js imports resolved/supported inside a 
> Graal.js/polyglot instance.
>
> e.g.
>
> Context context = context.create("js");
> context.eval("js", "import {x} from 'y.js'");
>
> currently it fails with.
>
> SyntaxError: Unnamed:474:0 Expected an operand but found import
> import x from y.js;out.print(render(taxon));
>
> Suggests it is not (yet) supported.
>
> This is not something that will block me from further experimentation 
> but working imports would be nice to have.
>
> Regards,
> Jerven
>



More information about the graal-dev mailing list