I have an ES6 module right.mjs. Executing it as a parameter to node works well:
$ node --version
v8.10.0
$ node --experimental-modu
Not precisely what was asked about (not really REPL), but (using node 12.6.0), it is possible to execute ESM code from command line via --eval:
.js extension instead of .mjs, put "type": "module" in package.json (see https://nodejs.org/api/esm.html#esm_enabling) to allow node treating JS files as modulesnode --experimental-modules --input-type=module --eval 'code here'You could alias this as esmeval for example:
alias esmeval='node --experimental-modules --input-type=module --eval'
And then you can use it as:
esmeval 'import { method } from "./path/to/utils.js"; console.log(method("param"))'
If you can't use node 12 yet as a primary version, but can in install via nvm, make the alias point to the v12 installation:
alias esmeval='/c/software/nvm/v12.6.0/node.exe --experimental-modules --input-type=module --eval'