我在package.json中使用一个本地模块,它也将react-native作为依赖项。
在我的应用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抛出:
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)我已经试过了
npm和yarn (升级)安装,但是react-native run-android抛出的错误总是相同的。发布于 2018-10-20 13:09:46
watchman watch-del-all
rm -rf node_modules && npm install
rm -fr $TMPDIR/react-*
npm cache clean
npm start -- --reset-cache发布于 2019-04-16 08:55:58
同样的问题也解决了!!
项目中的所有npm包都有节点模块。确保包中的node_modules目录不应包括已经存在的节点模块。
在我的例子中,react-native存在于我的项目的node_modules中,以及另一个分叉库的node_modules中。
由于库是分叉的,我可以从其中删除node_modules目录,问题就解决了。
发布于 2018-10-20 14:18:39
我自己回答。
作为一种临时解决方案,如果将依赖项放在peerDependencies中也不起作用,我已经将react和react-native放在了react-native-services包的devDependencies中。
https://stackoverflow.com/questions/52905842
复制相似问题