How to import an ES module in Node.js REPL?

后端 未结 3 1984
离开以前
离开以前 2020-12-09 09:28

I have an ES6 module right.mjs. Executing it as a parameter to node works well:

$ node --version
v8.10.0
$ node --experimental-modu         


        
3条回答
  •  被撕碎了的回忆
    2020-12-09 10:12

    This is currently impossible. ES modules are supposed to be imported from ES module scope, while REPL isn't considered one. This can improve with time because the support of ES modules is experimental. The use of require and import is mutually exclusive in Node module implementation, REPL already uses require.

    The support for dynamic import is expected in REPL, it isn't supported yet, the latest Node 11 release causes an error:

    TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.

提交回复
热议问题