Babel unexpected token import when running mocha tests

前端 未结 17 1541
Happy的楠姐
Happy的楠姐 2020-11-27 14:40

The solutions offered in other related questions, such as including the proper presets (es2015) in .babelrc, are already implemented in my project.

I have two projec

17条回答
  •  生来不讨喜
    2020-11-27 15:09

    I installed mocha and met the exact same error when I use import in my code. By doing the following actions, the issue was fixed.

    npm install babel-core --save-dev
    npm install babel-preset-es2015 --save-dev
    npm install babel-preset-stage-0 --save-dev
    

    And then add a .babelrc file:

    {
        "presets": [
            "es2015"
        ]
    }
    

    And then run mocha in this way:

    mocha --compilers js:babel-core/register
    

提交回复
热议问题