Unexpected reserved word 'import' when using babel

后端 未结 3 2114
有刺的猬
有刺的猬 2021-01-03 20:41

Using Babel in my NodeJSv4.1.1 code.

Got the require hook in:

require(\"babel-core/register\");

$appRoot = __dirname;

module.exports = require(\".         


        
3条回答
  •  我在风中等你
    2021-01-03 21:24

    Sounds like you aren't using the right presets. As of babel 6, the core babel loader no longer includes the expected ES6 transforms by default (it's now a generic code transformer platform), instead you must use a preset:

    require('babel-register')({
            "presets": ["es2015"]
    });
    

    You will also need to install the preset package:

    npm install --save-dev babel-preset-es2015
    

提交回复
热议问题