Babel unexpected token import when running mocha tests

前端 未结 17 1527
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:08

    I resolved this issue this morning with the following instructions from the official Using Babel instructions for Mocha 4:

    Install NPM Modules

    npm install --save-dev babel-polyfill
    npm install --save-dev babel-preset-env
    npm install --save-dev babel-register
    

    or a single command:

    npm i -d babel-polyfill babel-preset-env babel-register
    

    package.json:

    "scripts": {
        "test": "mocha --require babel-polyfill --require babel-register"
      }
    

    .babelrc

    {
      "presets": ["env"]
    }
    

提交回复
热议问题