Jest fails with “Unexpected token *” on import statement

前端 未结 5 609
南旧
南旧 2021-02-03 18:15

Why does Jest fail with \"Unexpected token *\" on a simple import statement...

Error log:

Admin@Admin-PC MINGW32 /d/project (master)
$ npm         


        
5条回答
  •  猫巷女王i
    2021-02-03 18:47

    Somewhere in your config file (.babelrc.js or package.json) you have to have "modules" under "presets" set to one of the "amd" | "umd" | "systemjs" | "commonjs" | "cjs" | "auto" | false.

    referer this fragment from the documentation

    something like this:

        "presets": [
      [
        "@babel/preset-env", {
          "targets": process.env.BABEL_TARGET === 'node' ? {
            "node": 'current'
          } : {
            "browsers": [ "last 2 versions" ]
          },
          "loose": true,
          "modules": 'commonjs'
        }
      ]
    ]
    

提交回复
热议问题