错误:无法找到模块' ErrorUtils'来自&env.js'

时间:2016-04-29 09:45:38

标签: react-native jestjs

我尝试使用jest with react-native卡住了这个错误。

"jest": {
  "scriptPreprocessor": "node_modules/react-native/jestSupport/preprocessor.js",
  "setupEnvScriptFile": "node_modules/react-native/jestSupport/env.js",
  "testDirectoryName": "__jest__"
}

这是我对package.json

的开玩笑键
react-native: 0.24.0
jest-cli: 12.0.2
babel-jest: 12.0.2

版本:

NodeJs

谢谢!

1 个答案:

答案 0 :(得分:1)

相同,react-native v0.24,jest v12。

我已报告了一个问题:https://github.com/facebook/jest/issues/974

要修补此问题,您应该删除该行(请参阅问题)

  1. node_modules/jestSupport复制到您的项目
  2. 修改jestSupport/env.js
  3. 注释掉jest.setMock('ErrorUtils', require('ErrorUtils'));
  4. 正确的top需要从相对于node_modules的路径。现在它是:require.requireActual('react-native/packager/react-packager/src/Resolver/polyfills/babelHelpers.js');
  5. 打开你的package.json并指定这个编辑过的env: { // ... "jest": { "setupEnvScriptFile": "<rootDir>/jestSupport/env.js", // ... } }