升级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等彻底清理并重新安装依赖:
- 进入iOS目录:
cd ios - 删除Pods文件夹:
rm -rf Pods - 删除Podfile.lock文件:
rm Podfile.lock - 删除Xcode缓存:
rm -rf ~/Library/Developer/Xcode/DerivedData - 重新执行:
pod install
- 进入iOS目录:
检查升级后的配置完整性:
确认Podfile中ReactCommon相关的配置是升级助手生成的默认内容,没有重复引入;同时清理Xcode项目Build Phases中可能残留的旧版本ReactCommon引用。
内容的提问来源于stack exchange,提问作者marko
相关产品推荐
相关产品推荐

