babel-node es6 “Modules aren't supported in the REPL”

前端 未结 2 1430
傲寒
傲寒 2021-01-13 05:17

babel-preset-es2015 is installed, and is OK with es6 feature just like below let a = 2;.
But can not work with es6 modules feature import

2条回答
  •  天涯浪人
    2021-01-13 05:28

    The error message is exactly what it says. You cannot use ES6 module syntax in the REPL, it is unsupported. You can create a small adapter that imports as ES6 and exports as CommonJS:

    # es6-to-common.js
    import MyThing from './somewhere';
    module.exports = MyThing;
    

    Now inside your usual babel-node prompt:

    > MyThing = require('./es6-to-common')
    

提交回复
热议问题