错误:jest-haste-map:使用本地依赖项时@providesModule命名冲突

时间:2018-10-20 12:51:16

标签: react-native npm jestjs yarnpkg

我正在package.json中使用一个本地模块,该模块也具有react-native作为依赖项。

在我的APP package.json中:

"react": "16.4.1",
"react-native": "0.56.0",
"react-native-services": "file:///Users/R01/Projects/react-native-services"

在我的react-native-services package.json中:

"react": "16.4.1",
"react-native": "0.56.0"

因此,在运行react-native run-android时,Metro Bundler会抛出:

Looking for JS files in
   /Users/R01/Projects/RNApp
   /Users/R01/Projects/react-native-services 


Metro Bundler ready.

Loading dependency graph...(node:72824) UnhandledPromiseRejectionWarning: Error: jest-haste-map: @providesModule naming collision:
  Duplicate module name: Sample
  Paths: /Users/R01/Projects/react-native-services/node_modules/react-native/Libraries/Sample/package.json collides with /Users/R01/Projects/RNApp/node_modules/react-native/Libraries/Sample/package.json

 This error is caused by a @providesModule declaration with the same name across two different files.
    at setModule (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:446:17)
    at workerReply (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:496:9)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)
(node:72824) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:72824) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
error: bundling failed: Error: jest-haste-map: @providesModule naming collision:
  Duplicate module name: Sample
  Paths: /Users/R01/Projects/react-native-services/node_modules/react-native/Libraries/Sample/package.json collides with /Users/R01/Projects/RNApp/node_modules/react-native/Libraries/Sample/package.json

This error is caused by a @providesModule declaration with the same name across two different files.
    at setModule (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:446:17)
    at workerReply (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:496:9)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)

我已经尝试过:

  • 同时安装了npmyarn(升级),但是react-native run-android总是抛出相同的错误。
  • watchman watch-del-all rm -rf node_modules && npm install rm -fr $ TMPDIR / react- * npm cache clean npm start--重置缓存

5 个答案:

答案 0 :(得分:0)

watchman watch-del-all

rm -rf node_modules && npm install

rm -fr $TMPDIR/react-*
npm cache clean
npm start -- --reset-cache

for more check out here

答案 1 :(得分:0)

我回应自己。

作为一个临时解决方案,考虑到将依赖项放在peerDependencies中也不起作用,我将reactreact-native放在{的devDependencies {1}}包。

答案 2 :(得分:0)

我也遇到了同样的错误。我尝试了以下步骤,它的工作方式很迷人。

请从“%appdata%\ Temp”中删除所有反应本机特定的文件夹,然后尝试以下命令:

rimraf node_modules
npm cache clean --force
npm install
rm -rf ios/build

/Users/Jebasuthan/XcodeProject/Game/ios/Pods/React/package.json更改为其他内容

非递归

Xcode change

答案 3 :(得分:0)

面对同样的问题 解决了!!

项目中所有npm软件包都具有节点模块。 确保包内的node_modules目录不应包含已经存在的节点模块。

在我的情况下,项目的node_modules和另一个分支库的node_modules中都存在react-native

由于库是分叉的,所以我可以从中删除node_modules目录,问题得到解决。

答案 4 :(得分:0)

const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
 resolver: {
    blacklistRE: blacklist([
        /node_modules\/.*\/node_modules\/react-native\/.*/,
    ])
 },
};