Unexpected reserved word 'import' when using babel

后端 未结 3 2109
有刺的猬
有刺的猬 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:30

    It seems that this file is not being transpiled. Is this subsequently loaded .js file in the node_modules directory? If so, you need to:

    require("babel-core/register")({
      // This will override `node_modules` ignoring - you can alternatively pass
      // an array of strings to be explicitly matched or a regex / glob
      ignore: false
    });
    

    By default all requires to node_modules will be ignored. You can override this by passing an ignore regex

    https://babeljs.io/docs/usage/require/

提交回复
热议问题