【问题标题】:Create React App executing tests with jest Unexpected identifier使用 jest Unexpected identifier 创建 React App 执行测试
【发布时间】:2018-11-07 16:08:40
【问题描述】:

我正在 CRA 中尝试用 jest 执行测试,但我不断收到这个奇怪的错误。

C:\Users\mfonpah\Documents\projects\nexus-web-client\web- 
client\node_modules\auth0-js\src\index.js:1
(function (exports, require, module, __filename, __dirname) { import 
Authentication from './authentication';                                                                     
^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:74:7)
at createScript (vm.js:246:10)
at Object.runInThisContext (vm.js:298:10)
at Module._compile (internal/modules/cjs/loader.js:670:28)
at Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Object.require.extensions.(anonymous function) [as .js] 
(C:\Users\mfonpah\Documents\projects\nexus-web-client\web- 
client\node_modules\babel-register\lib\node.js:152:7)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)

关于如何解决这个问题的任何想法? 谢谢

【问题讨论】:

    标签: ecmascript-6 jestjs create-react-app babel-jest


    【解决方案1】:

    如果您看到此错误,则说明您的 EF6 导入语句没有被转译。确保你的 babel 预设包含“env”

    package.json 中的

    .babelrc"babel" 属性

    {
        "presets":["env", "react"]
    }
    

    根据您的用例,您可能还需要添加transform-es2015-modules-amd 插件more here

    【讨论】:

      猜你喜欢
      • 2019-10-28
      • 2019-10-26
      • 2019-09-16
      • 2018-03-17
      • 1970-01-01
      • 2020-07-22
      • 2017-07-04
      • 2018-09-11
      • 2021-01-22
      相关资源
      最近更新 更多