更新MacOS与Xcode 15.4后执行pod install报错求助
解决Monorepo React Native项目Pod Install报错:无法加载nx_post_install文件
问题背景
MacOS升级至14.6.1、Xcode升级至15.4后,在Monorepo结构的React Native项目执行pod install时触发报错:
[!] Invalid
Podfilefile: cannot load such file -- /Users/zzz/Documents/GitHub/project/apps/mobile/node_modules/@nrwl/react-native/nx_post_install
项目核心环境:
- React Native 0.68.2、React 18.2.0
- Cocoapods 1.15.2、Ruby 2.6.10p210
- 设备:Apple M2
- 依赖版本:@nrwl/react-native@14.4.3
核心原因
Podfile中引用的nx_post_install路径错误,Monorepo的node_modules存放在项目根目录,而非apps/mobile子目录下;同时老旧版本的@nrwl/react-native可能与新版Xcode存在兼容冲突。
解决方案
1. 修正Podfile路径
打开apps/mobile/ios/Podfile,将错误的路径引用修改为指向根目录node_modules:
# 原错误路径 # require_relative '../node_modules/@nrwl/react-native/nx_post_install' # 修改为(回退两层到项目根目录) require_relative '../../node_modules/@nrwl/react-native/nx_post_install'
2. 重装依赖并清理Pod缓存
在项目根目录执行以下命令:
rm -rf node_modules package-lock.json yarn.lock npm install # 或 yarn install cd apps/mobile/ios pod deintegrate pod install
3. 适配Xcode 15.4兼容问题(可选)
若修改路径后仍报错,说明@nrwl/react-native@14.4.3版本过老,可升级到14.x系列最新稳定版(如14.8.6),或手动修改node_modules/@nrwl/react-native/nx_post_install.rb中的逻辑,适配Xcode 15.4的编译规则。
4. 临时注释Nx相关逻辑(应急方案)
若无需Nx的post install处理,可临时注释Podfile中相关代码:
# 注释引用 # require_relative '../../node_modules/@nrwl/react-native/nx_post_install' # 注释post_install中的调用 post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) # nx_post_install(installer) end
验证
进入apps/mobile/ios目录,重新执行pod install,确认无报错即可。
内容的提问来源于stack exchange,提问作者mimiranda
相关产品推荐
相关产品推荐

