我收到错误:
模糊解析:模块" ... / myModule.js"试图要求 ' react-native',但有几个文件提供此模块。您 可以删除或修复它们:
... / MyProject的/ IOS /荚/阵营/的package.json
... / MyProject的/ node_modules /反应天然/的package.json
我几乎可以肯定这是因为使用Podfiles,特别是当他们安装" React"夹。但是,我必须使用Podfiles才能安装react-native-firebase
。话虽如此,当我删除我的Pods文件夹下的React文件夹(ios / Pods / React)时,我再也无法使用react-native-firebase
了。
GitHub周围有一个修复程序,建议在Podfile中附加:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "React"
target.remove_from_project
end
end
end
但这对我不起作用。有没有人遇到过这个问题?
如果相关,这是我正在使用的podfile:
platform :ios, '8.0'
target 'MyProject2' do
pod 'Firebase/Core'
pod 'Firebase/Database'
pod 'Firebase/Messaging'
pod 'RNSVG', :path => '../node_modules/react-native-svg'
target 'MyProject2Tests' do
inherit! :search_paths
# Pods for testing
end
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "React"
target.remove_from_project
end
end
end
end
编辑:当我删除' RNSVG'从我的Podfile中,我得到一个错误说明:"不变违规:RNSVGPath'' RNSVGPath'不存在"。我已经运行了react-native链接,并按照react-native-svg
的手动安装说明进行操作。
答案 0 :(得分:1)
我不得不手动将React pod链接到node_modules
:
pod 'React', :path => '../node_modules/react-native'
答案 1 :(得分:0)
在使我的应用程序适用于iOS时,我刚刚完成了解决此问题的工作。
我使用了克里斯的解决方案,而且...
仓促的包装经理正在从我的根node_modules
文件夹和Build文件夹内的node_modules
文件夹中找到我的模块的实例。
要解决此问题,请在项目的根目录中创建一个名为rn-cli.config.js
的文件:
const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
resolver: {
blacklistRE: blacklist([
/Build\/.*/,
])
},
};
答案 2 :(得分:0)
只要添加带有React依赖项的Pod,似乎都会发生此问题。
一旦某些东西具有react依赖性并且未添加React Pod,它将经常尝试安装它,并在CocoaPods(0.11)上找到旧版本的React。
为避免这种情况,您需要按照此处的react-native文档显式添加依赖项和必需的子依赖项:react-native cocoapods docs。
例如,当我添加react-native-community/async-storage
模块时,我必须将所有这些添加到我的podfile中,该文件以前只有AppCenter和Firebase相关的依赖项:
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'CxxBridge', # Include this for RN >= 0.47
'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
'RCTText',
'RCTNetwork',
'RCTWebSocket', # Needed for debugging
'RCTAnimation', # Needed for FlatList and animations running on native UI thread
# Add any other subspecs you want to use in your project
]
# Explicitly include Yoga if you are using RN >= 0.42.0
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'
答案 3 :(得分:-1)
看一下react-native-svg
,他们的Podfile将React指定为依赖项。为了简单起见,我建议您使用推荐的react-native link
命令来安装此库,而不是在Podfile中指定它。
删除react-native-svg
后,您可能需要清除Podfile
文件夹并重新运行pod install