jest: Test suite failed to run, SyntaxError: Unexpected token import

前端 未结 6 1740
粉色の甜心
粉色の甜心 2020-12-01 20:44

This is my jest configuration from the package.json file:

\"jest\": {
    \"automock\": false,
    \"browser\": true,
    \"moduleNameMapper\": {
      \"\\\         


        
6条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 21:16

    The following .babelrc works for me (without additions):

    {
      "presets": [["env", {
        "debug": false,
        "modules": false
      }],  "es2015", "stage-0", "react"],
      "plugins": [
        "react-hot-loader/babel",
        "syntax-dynamic-import",
        "dynamic-import-node",
        "transform-class-properties",
        "transform-decorators-legacy"
      ]
    }
    

    "devDependencies" section of package.json looks like this:

    ...
    "devDependencies": {
      "babel-cli": "latest",
      "babel-core": "^6.26.3",
      "babel-eslint": "^8.2.3",
      "babel-jest": "^22.4.4",
      "babel-loader": "latest",
      "babel-plugin-dynamic-import-node": "^1.2.0",
      "babel-plugin-lodash": "latest",
      "babel-plugin-syntax-dynamic-import": "^6.18.0",
      "babel-plugin-transform-class-properties": "^6.24.1",
      "babel-plugin-transform-decorators-legacy": "latest",
      "babel-plugin-transform-dynamic-import": "^2.0.0",
      "babel-plugin-transform-flow-strip-types": "^6.22.0",
      "babel-plugin-transform-object-rest-spread": "latest",
      "babel-polyfill": "^6.26.0",
      "babel-preset-env": "^1.7.0",
      "babel-preset-flow": "^6.23.0",
      "babel-preset-react": "^6.24.1",
      "babel-preset-react-app-babel-7": "^4.0.1",
      "babel-preset-stage-0": "^6.24.1",
     ...
    

提交回复
热议问题