React Native项目构建失败:React-rncore目标提示目录不存在
React Native iOS构建报错:/Users/[user]/Library/Mobile: No such file or directory
问题描述
一个长期未维护的React Native项目,此前运行正常,现在构建时出现路径不存在错误,核心提示:
build target react-rncore /Users/[user]/Library/Mobile: No such file or directory
已尝试操作
- 更新Xcode至15.2版本
- 清理Xcode构建文件夹
- 删除Derived Data
- 重装所有依赖,执行命令:
rm -rf node_modules/ npm install cd ios/ rm -rf Pods/ Podfile.lock pod install
环境信息
macos: 14.3.1, xcode: 15.2 15C500b, mac air m1 13
完整错误日志
Build target React-rncore of project Pods with configuration Debug PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/eliaelhadad/Library/Developer/Xcode/DerivedData/danoAesthetics-ddpibeemzkenrfdsrluevuazikkd/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-rncore.build/Script-46EB2E0003AA50.sh (in target 'React-rncore' from project 'Pods') cd /Users/eliaelhadad/Library/Mobile\ /bin/sh: /Users/eliaelhadad/Library/Mobile: No such file or directory Command PhaseScriptExecution failed with a nonzero exit code /Users/eliaelhadad/Library/Mobile: No such file or directory Command PhaseScriptExecution failed with a nonzero exit code
解决方法
1. 修正Podfile中的路径引用
打开iOS目录下的Podfile,检查是否存在错误截断的路径(比如把带空格的Mobile Documents写成了Mobile),如果有,用双引号包裹完整路径,或对空格添加转义符\ 。
2. 修复Xcode脚本中的cd路径
- 打开Xcode,进入Pods项目的
React-rncore目标 - 切换到
Build Phases标签,找到[CP-User] Generate Specs脚本 - 日志显示脚本执行
cd /Users/eliaelhadad/Library/Mobile\路径不完整,手动修正为实际存在的完整路径(比如包含Mobile Documents的正确路径)
3. 适配Xcode版本降级React Native
老版本React Native可能和Xcode 15不兼容,尝试降级到0.72.x或0.73.x等适配Xcode 15的稳定版本,之后重新执行依赖安装和pod install。
4. 修复用户目录权限
执行命令确保当前用户对Library目录有读写权限:
sudo chown -R $USER:$GROUP ~/Library/
内容的提问来源于stack exchange,提问作者Nufkin
相关产品推荐
相关产品推荐

