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

前端 未结 6 1745
粉色の甜心
粉色の甜心 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 20:55

    Jest sets the env variable to test, so I had to add my presets to the env setting in .babelrc:

    {
      "plugins": ["syntax-dynamic-import", "transform-runtime"],
      "presets": [
        [
          "es2015",
          {
            "modules": false
          }
        ],
        "react",
        "stage-0"
      ],
      "env": {
        "start": {
          "presets": [
            "react-hmre"
          ]
        },
        "test": {
          "presets": ["es2015", "react", "stage-0"]
        }
      }
    }
    

提交回复
热议问题