standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 147 forks source link

Not working with code run by `vm.runInThisContext` #886

Open n-riesco opened 3 years ago

n-riesco commented 3 years ago

I've created the file index.mjs with:

const test = "test";
export default test;

and run the following:

$ node -r esm
> import test1 from '.';
> test1
'test'
> vm.runInThisContext("import test2 from '.';")

Uncaught:
Syntax Error: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import
>

esm works with the code run by Node.js REPL, but it doesn't with the code run by vm.runInThisContext


I've searched other issues: #791 maybe related.


The test was run with Node v14.8.0