重复的模块名称:react-native
Posted
技术标签:
【中文标题】重复的模块名称:react-native【英文标题】:Duplicate Module Name: react-native 【发布时间】:2018-06-11 20:45:59 【问题描述】:我在我的 XCode 项目中运行了Pod Update
,现在由于下载了重复的模块,我的项目无法编译。有谁知道解决办法吗?
Looking for JS files in
/Users/.../App/Finalv2
Metro Bundler ready.
Loading dependency graph...jest-haste-map: @providesModule naming collision:
Duplicate module name: react-native
Paths: /Users/.../App/Finalv2/node_modules/react-native/package.json collides with /Users/.../App/Finalv2/ios/Pods/React/package.json
This warning is caused by a @providesModule declaration with the same name across two different files.
Loading dependency graph, done.
更新:
我删除了我的 node_modules
文件夹和 package.lock.json
并运行了 npm install
但问题仍然存在
编辑:
添加我的Package.json
"name": "sample-app",
"version": "0.0.1",
"private": true,
"scripts":
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
,
"dependencies":
"@expo/vector-icons": "^6.2.2",
"art": "^0.10.1",
"axios": "^0.17.1",
"expo": "^24.0.2",
"firebase": "^4.6.0",
"lodash": "^4.17.4",
"moment": "^2.19.3",
"native-base": "^2.3.3",
"prop-types": "^15.6.0",
"react": "^16.3.1",
"react-native": "^0.55.3",
"react-native-camera": "^0.10.0",
"react-native-circular-progress": "git+https://github.com/kk1429/react-native-circular-progress.git",
"react-native-countdown-circle": "^2.0.0",
"react-native-country-picker-modal": "^0.5.1",
"react-native-device-info": "^0.13.0",
"react-native-easy-grid": "^0.1.16",
"react-native-elements": "^0.18.5",
"react-native-fcm": "^11.2.0",
"react-native-fetch-blob": "^0.10.8",
"react-native-firebase": "^4.1.0",
"react-native-linear-gradient": "^2.4.0",
"react-native-linkedin": "^1.2.1",
"react-native-material-ui": "^1.19.0",
"react-native-navigation": "^1.1.471",
"react-native-progress": "^3.4.0",
"react-native-pull-refresh": "^1.0.0",
"react-native-rename": "^2.2.2",
"react-native-svg": "^5.4.2",
"react-native-svg-animated-linear-gradient": "^0.1.8",
"react-native-swiper": "^1.5.13",
"react-native-tag-input": "git+https://github.com/kk1429/react-native-tag-input.git",
"react-native-thumbnail-video": "0.0.8",
"react-native-vector-icons": "^4.4.2",
"react-native-video": "^2.0.0",
"react-navigation": "^1.0.0-beta.19",
"react-redux": "^5.0.6",
"react-save-refs": "^1.0.2",
"redux": "^3.7.2",
"redux-devtools-extension": "^2.13.2",
"redux-persist": "^5.3.4",
"redux-thunk": "^2.2.0",
"whatwg-fetch": "^2.0.3"
,
"devDependencies":
"babel-jest": "22.1.0",
"babel-preset-react-native": "4.0.0",
"jest": "22.1.4",
"react-test-renderer": "16.2.0"
,
"jest":
"preset": "react-native"
,
"rnpm":
"assets": [
"./assets/fonts/"
]
更新
运行 npm install
给出一个奇怪的错误
> fsevents@1.2.4 install /Users/.../App/Finalv2/node_modules/fsevents
> node install
[fsevents] Success: "/Users/.../App/Finalv2/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
> grpc@1.10.1 install /Users/kaaddevelopers/Documents/Clipme/App/Finalv2/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library
node-pre-gyp ERR! Tried to download(403): https://storage.googleapis.com/grpc-precompiled-binaries/node/grpc/v1.10.1/node-v64-darwin-x64-unknown.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for grpc@1.10.1 and node@10.1.0 (node-v64 ABI, unknown) (falling back to source compile with node-gyp)
【问题讨论】:
你在使用react-native-router-flux
吗?
没有。我没有使用那个。我正在使用react-native-navigation
请添加您的package.json
,以便我查看您拥有哪些库!
完成。编辑帖子
【参考方案1】:
我只是花了一些时间寻找解决方案,终于找到了可行的方法!我没有使用 Firebase,但这里的讨论能够提供帮助:https://github.com/invertase/react-native-firebase/issues/414 您必须在 Podfile 中添加两行。
# Add these to your Podfile
pod 'React', :path => '../node_modules/react-native'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
然后运行以下命令以确保重新安装 CocoaPods。
cd ios
rm -rf Pods
pod install
【讨论】:
仅针对遇到此帖子的其他人:此解决方案对我有用(删除和重新安装 pod 至关重要)。也许它应该是公认的答案?谢谢德里! 谢谢@Dehli,你的解决方案真的很有帮助。在 pod installreact-native start --reset-cache
之后只需要一个额外的命令。
感谢 m8。这很有帮助。我在我的项目中同时使用 Firebase 和 Bugsnag,它为我解决了这个问题。【参考方案2】:
试试:
watchman watch-del-all
rm -fr $TMPDIR/react-*
erase jest-cache folder
rm -rf node_modules
npm install
npm cache clean && npm start -- --reset-cache
更新
同时尝试download the latest node js 并运行npm install -g npm
【讨论】:
你能回滚Pod Update
吗?
我想我将不得不创建一个新项目并从头开始导入源代码:/
这对我有用。我正在使用 expo 运行我的应用程序以供参考。所有其他解决方案从未对我有用。谢谢!【参考方案3】:
删除“Pod”文件夹中的“React”文件夹
在最后一个end
之后的底部的 pod 文件中添加此内容
post_install do |installer|
installer.pods_project.targets.each do |target|
# The following is needed to ensure the "archive" step works in XCode.
# It removes React & Yoga from the Pods project, as it is already included in the main project.
# Without this, you'd see errors when you archive like:
# "Multiple commands produce ... libReact.a"
# "Multiple commands produce ... libyoga.a"
targets_to_ignore = %w(React yoga)
if targets_to_ignore.include? target.name
target.remove_from_project
end
end
end
删除您的 Pods
文件夹,然后继续
pod install
【讨论】:
每pod install
后会重新添加一次【参考方案4】:
添加到@Dehli 的答案,如果发生这种情况:
您将 react-native 作为 react-native 模块的“依赖项”
解决方案:将 react-native 移至 package.json 中的“peerDependency”
您已移至 peerDependency 并让您的应用程序的 package-lock.json 将 react-native 列为对您的模块的依赖项
解决方案:删除应用程序中的 package-lock.json,清理 npm_modules 文件夹并再次运行npm install
【讨论】:
【参考方案5】:在我的例子中,因为我通过 pod 链接了一个库,所以它会自动安装响应 pod。所以我更新了我的 podfile:
target 'MyProject' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
rn_path = '../node_modules/react-native'
pod 'React', path: rn_path, subspecs: [
'Core',
'CxxBridge',
'DevSupport',
'RCTActionSheet',
'RCTAnimation',
'RCTGeolocation',
'RCTImage',
'RCTLinkingIOS',
'RCTNetwork',
'RCTSettings',
'RCTText',
'RCTVibration',
'RCTWebSocket',
]
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
//Another libraries here
pod 'RNImageTools', :path => '../node_modules/react-native-image-tools-wm'
post_install do |installer|
installer.pods_project.targets.each do |target|
# The following is needed to ensure the "archive" step works in XCode.
# It removes React & Yoga from the Pods project, as it is already included in the main project.
# Without this, you'd see errors when you archive like:
# "Multiple commands produce ... libReact.a"
# "Multiple commands produce ... libyoga.a"
targets_to_ignore = %w(React yoga)
if targets_to_ignore.include? target.name
target.remove_from_project
end
end
end
end
然后我删除Pods
文件夹并运行pod install
。
就这些。
【讨论】:
【参考方案6】:此问题的根本原因是您的监视文件夹(包括 projectRoot)中有多个 react-native
模块的副本。
-
您可以通过重新安装删除那些重复的,就像许多建议的答案一样。
如果不能,通过blacklist选项忽略其他人
【讨论】:
以上是关于重复的模块名称:react-native的主要内容,如果未能解决你的问题,请参考以下文章
React-Native Packager 失败:重复的模块名称