首页 文章

React Native:Podfiles导致名称共谋

提问于
浏览
5

我收到一个错误:

模糊解析:模块“... / myModule.js”尝试要求'react-native',但有几个文件提供此模块 . 您可以删除或修复它们:... / MyProject / ios / Pods / React / package.json ... / MyProject / node_modules / react-native / 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

编辑:当我从我的Podfile中删除'RNSVG'时,出现错误说明:"Invariant Violation: Native component for 'RNSVGPath' does not exist" . 我已经运行了react-native链接,并按照 react-native-svg 的手动安装说明进行操作 .

2 回答

  • 1

    我不得不手动将React pod连接到 node_modules

    pod 'React', :path => '../node_modules/react-native'

  • -1

    看一下 react-native-svg ,他们的Podfile将React指定为依赖项 . 为了简单起见,我建议您使用推荐的 react-native link 命令来安装此库,而不是在Podfile中指定它 .

    删除 react-native-svg 后,您可能需要清除 Podfile 文件夹并重新运行 pod install

相关问题