Unexpected reserved word 'import' when using babel

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

    I was hitting the problem when trying to run tests via mocha, and I solved it by putting this in my package.json file:

    "babel": {
        "presets": [
          "es2015"
        ]
    },
    

    I'm not completely clear on how this works. I'm running tests like this:

    mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive
    

    Eventually, this will all make sense I suppose.

提交回复
热议问题