在 React-Native 项目中开玩笑。如何将重复模块列入黑名单或删除?

Jest in a React-Native project. How to Blacklist or delete duplicate modules?

我正在尝试使用 lerna 建立一个 React-Native 项目。当我尝试 运行 jest 时,我遇到以下错误。

   The name `setupDevtools` was looked up in the Haste module map. It cannot be resolved, because there exists several different files, or packages, that provide a module for that particular name and platform. The platform is generic (no extension). You must delete or blacklist files until there remains only one of these:

      * `/Users/kevin.amiranoff/project/node_modules/react-native/Libraries/Core/Devtools/setupDevtools.js` (module)
      * `/Users/kevin.amiranoff/project/packages/App/node_modules/react-native/Libraries/Core/Devtools/setupDevtools.js` (module)
      * `/Users/kevin.amiranoff/project/packages/App-exceptions/node_modules/react-native/Libraries/Core/Devtools/setupDevtools.js` (module)
      * `/Users/kevin.amiranoff/project/packages/App-signin/node_modules/react-native/Libraries/Core/Devtools/setupDevtools.js` (module)
      * `/Users/kevin.amiranoff/project/packages/App-ui/node_modules/react-native/Libraries/Core/Devtools/setupDevtools.js` (module)
      * `/Users/kevin.amiranoff/project/packages/App-utils/node_modules/react-native/Libraries/Core/Devtools/setupDevtools.js` (module)

这是我的 jest 在根 package.json

中的配置
"jest": {
    "preset": "react-native",
    "globals": {
      "__DEV__": true
    },
    "testRegex": "packages/(.*)/src/(.*)/__tests__/(.*).js?$",
    "transformIgnorePatterns": [
      "packages/(.*)/node_modules/?!(react|react-native)"
         ],
    "testEnvironment": "node"
  }

任何人都可以向我解释我必须忽略什么以及如何忽略?

您应该使用 modulePathIgnorePatterns 来忽略某些目录。 确保只有您真正想要使用的那个不在此忽略列表中。

Link 到文档: https://facebook.github.io/jest/docs/en/configuration.html#modulepathignorepatterns-array-string