React Native 的项目 今天安装了三方库react-native-camera和react-native-sound及react-native-permissions,期间都需要执行react-native link命令安装对应的原生依赖, 执行命令完成之后再执行npm start启动项目,结果傻眼了,报错如下:
Loading dependency graph...(node:6490) UnhandledPromiseRejectionWarning: Error: jest-haste-map: Haste module naming collision:
Duplicate module name: react-native
Paths: /Users/stephen/Documents/StephenHtmlProjects/ReactNativeDoorAuth/ios/Pods/React/package.json collides with /Users/stephen/Documents/StephenHtmlProjects/ReactNativeDoorAuth/node_modules/react-native/package.json
This error is caused by `hasteImpl` returning the same name for different files.
at setModule (/Users/stephen/Documents/StephenHtmlProjects/ReactNativeDoorAuth/node_modules/jest-haste-map/build/index.js:569:17)
at workerReply (/Users/stephen/Documents/StephenHtmlProjects/ReactNativeDoorAuth/node_modules/jest-haste-map/build/index.js:641:9)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:6490) 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:6490) [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.
(node:6490) UnhandledPromiseRejectionWarning: Error: jest-haste-map: Haste module naming collision:
Duplicate module name: react-native
Paths: /Users/stephen/Documents/StephenHtmlProjects/ReactNativeDoorAuth/ios/Pods/React/package.json collides with /Users/stephen/Documents/StephenHtmlProjects/ReactNativeDoorAuth/node_modules/react-native/package.json
This error is caused by `hasteImpl` returning the same name for different files.
at setModule (/Users/stephen/Documents/StephenHtmlProjects/ReactNativeDoorAuth/node_modules/jest-haste-map/build/index.js:569:17)
at workerReply (/Users/stephen/Documents/StephenHtmlProjects/ReactNativeDoorAuth/node_modules/jest-haste-map/build/index.js:641:9)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:6490) 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: 3)
Job 4, 'npm start' has stopped
,顿时分析了哈,主要是这句Duplicate module name: react-native,说两个路径下存在相同的module:react-native,就是冲突了,但是怎么解决呢,第三方的库也不好改得,于是各种百度:
几乎接近点的答案是:
1.watchman watch-del-all
2.rm -rf node_modules && npm install
3.rm -rf $TMPDIR/*
4.npm start -- --reset-cache
很显然,结果不好使,于是分析乎,是我执行了新依赖命令导致的问题,而且报错里面有提到时ios的pod依赖下导致的冲突,果断瞧哈ios的pod文件,发现link命令在pod文件加了:
1.pod 'react-native-camera', :path => '../node_modules/react-native-camera'
2.pod 'RNSound', :path => '../node_modules/react-native-sound'
3.pod 'react-native-permissions', :path => '../node_modules/react-native-permissions'
于是猜测应该是这些库依赖了react native,然后导致的冲突,果断注释这三句和react native有关的,然后命令行到ios目录执行:pod install,看输出日志上就有:Removing React这句,想来方向对了,等命令执行完后,返回上级目录执行npm start --reset-cache启动项目,果然ok了,然后以为会影响ios打包,结果测试了,没问题,爽