Use import in javascript being called from Java program through graalvm

Viewed 68

I am trying out Graalvm for a use case and I was wondering if I can use import statements in the javascript being called from java. I have tried both:

context.eval("js", "import v4 from 'uuid';var o = v4();");

which gives the error Expected an operand but found import import v4 from 'uuid';var o = v4();

and

creating a separate script containing

import v4 from 'uuid';
var uu = v4();

then running the script via

InputStream inputStream = Controller.class.getResourceAsStream("/script.js");
String script = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
context.eval("js", script);

which returns the same error: Expected an operand but found import import v4 from 'uuid';

I went through the docs and it seems like it is possible. Can someone please guide me towards the correct approach?

0 Answers
Related