【问题标题】:React Native: Podfiles causing name collusionsReact Native:Podfile 导致名称冲突
【发布时间】:2018-03-21 15:39:26
【问题描述】:

我收到一个错误:

不明确的解决方案:模块“.../myModule.js”试图要求 'react-native',但是有几个文件提供了这个模块。你 可以删除或修复它们:

.../MyProject/ios/Pods/React/package.json

.../MyProject/node_modules/react-native/package.json

我几乎可以肯定这是由于使用了 Podfiles,特别是当他们安装“React”文件夹时。但是,我必须使用 Podfiles 才能安装 react-native-firebase。话虽如此,当我删除 Pods 文件夹 (ios/Pods/React) 下的 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' 时,我收到一条错误消息:“不变违规:'RNSVGPath' 的本机组件不存在”。我已经运行了 react-native 链接并按照 react-native-svg 的手动安装说明进行操作。

【问题讨论】:

    标签: reactjs react-native cocoapods react-native-firebase


    【解决方案1】:

    我必须手动将 React pod 链接到 node_modules

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

    【讨论】:

    • 太棒了,但我发现我还需要添加一个子规范部分!
    【解决方案2】:

    在使我的应用适用于 iOS 时,我刚刚解决了这个问题。

    我使用了 Chris 的解决方案,还...

    匆忙的打包管理器正在从我的根 node_modules 文件夹和我的 Build 文件夹内的 node_modules 文件夹中查找我的模块实例。

    要解决这个问题,请在项目的根目录中创建一个名为 rn-cli.config.js 的文件:

    const blacklist = require('metro-config/src/defaults/blacklist');
    
    
    module.exports = {
    resolver: {
    blacklistRE: blacklist([
                            /Build\/.*/,
                            ])
    },
    };
    

    【讨论】:

      【解决方案3】:

      这个问题似乎在任何时候添加一个带有 React 依赖的 Pod 时都会发生。

      一旦某个东西具有 react 依赖并且没有添加 React Pod,它通常会尝试安装它,在 CocoaPods (0.11) 上找到旧版本的 React。

      为避免这种情况,您需要根据此处的 react-native 文档显式添加依赖项和所需的子依赖项:react-native cocoapods docs

      例如,当我添加 react-native-community/async-storage 模块时,我必须将所有这些添加到我以前只有 AppCenter 和 Firebase 相关依赖项的 podfile 中:

        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'
      

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

        • 当我这样做时,我得到一个“不变的冲突:'RNSVGPath' 的本机组件不存在”。尽管如此,我都运行了“react-native link”并按照手动安装 react-native-svg 的步骤操作。
        • 根据我的观察,react-native 链接将库添加到 Podfile,因此应该会产生相同的效果。
        猜你喜欢
        • 1970-01-01
        • 2014-04-06
        • 1970-01-01
        • 2021-06-06
        • 1970-01-01
        • 2018-11-27
        • 1970-01-01
        • 2017-10-31
        相关资源
        最近更新 更多