Hi Olivier, Support for ECMAScript 6 is quite incomplete in Nashorn unfortunately. We only support a small set of ES6 features in JDK 9:
• Template strings • let, const, and block scope • Iterators and for..of loops • Map, Set, WeakMap, and WeakSet • Symbols • Binary and octal literals „require“ on the other hand is not part of ES6. It was created as a way to implement modules in the pre-ES6 world. It can be implemented in script and there are implementations out there, so this is probably the most promising approach to use modules in Nashorn. Hannes > Am 08.01.2018 um 17:33 schrieb Olivier <olivier.lediou...@oracle.com>: > > Hi experts, > I want to run ES6 scripts from Java, using Nashorn. > I have scripts involving 'let', 'const', my Java code is happy with it, I > just need to use a property "nashorn.args" set to "--language=es6". > > Now, I'd like to move forward, use imports and modules. > I have one script like this (modules.01.js): > > function displayMessage() { > console.log("Hello JS World!"); > }; > > export default displayMessage; > > I want to consume it from this (modules.consume.js): > > import displayMessagefrom './modules.01'; > > displayMessage(); > > But this is where I have a question: > My engine.eval("load('./modules.consume.js');"); complains about the "import" > statement. > In the transpiled version, it complains about the "require" statement. > > I must be missing something... I attach my code, in case it's needed. > > Any idea, pointer, comment, help, etc, most welcome, > Thank you! > - Olivier > > > > <Executor.java>