You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级React Native 0.74.1后iOS构建失败:ReactCommon模块重定义

问题

严格遵循React Native升级助手完成从0.71.1到0.74.1的版本升级,随后将其他依赖更新至最新版本。执行pod install时遇到问题,通过删除Pods文件夹和锁文件解决;为使Firebase pod正常安装,在Podfile中添加了use_modular_headers!。但构建iOS项目时出现以下错误:

/Users/marko/App/Livestream/ios/Pods/Headers/Public/ReactCommon/ReactCommon.modulemap:1:8: error: redefinition of module 'ReactCommon'
module ReactCommon {
       ^
/Users/marko/App/Livestream/ios/Pods/Headers/Public/ReactCommon/React-RuntimeApple.modulemap:1:8: note: previously defined here
module ReactCommon {
       ^
1 error generated.

请问能否直接重命名其中一个ReactCommon模块?

解决方案

不建议直接重命名ReactCommon模块,因为React Native内部多个组件依赖该模块的命名关联,手动修改会引发更多依赖冲突或编译问题,更稳妥的解决方法如下:

  • 调整Podfile的模块化头配置:移除全局的use_modular_headers!,仅针对Firebase相关依赖启用模块化头,避免影响React Native内部模块:

    # 移除全局的use_modular_headers!
    # use_modular_headers!
    
    # 为用到的Firebase组件单独启用模块化头
    pod 'Firebase', :modular_headers => true
    pod 'FirebaseCore', :modular_headers => true
    # 根据项目实际使用的组件添加,比如FirebaseAuth、FirebaseFirestore等
    
  • 彻底清理并重新安装依赖:

    1. 进入iOS目录:cd ios
    2. 删除Pods文件夹:rm -rf Pods
    3. 删除Podfile.lock文件:rm Podfile.lock
    4. 删除Xcode缓存:rm -rf ~/Library/Developer/Xcode/DerivedData
    5. 重新执行:pod install
  • 检查升级后的配置完整性:
    确认Podfile中ReactCommon相关的配置是升级助手生成的默认内容,没有重复引入;同时清理Xcode项目Build Phases中可能残留的旧版本ReactCommon引用。

内容的提问来源于stack exchange,提问作者marko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 11:17:07