无法获取同路径下已存在文件的路径,Xcode脚本执行失败
解决Xcode执行React Native脚本时找不到with-environment.sh的问题
错误信息
export variant=normal /bin/sh -c /Users/isu_412/Library/Developer/Xcode/DerivedData/NativeReactApp-dkrfgomnguztvibkwwhdadnfezll/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/ReactNativeDependencies.build/Script-45C7A1B4D9F210EACAF8C62608FE5A15.sh /Users/isu_412/Library/Developer/Xcode/DerivedData/NativeReactApp-dkrfgomnguztvibkwwhdadnfezll/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/ReactNativeDependencies.build/Script-45C7A1B4D9F210EACAF8C62608FE5A15.sh: 第2行: /Users/isu_412/Desktop/NativeReactApp/Pods/../../ReactNative/node_modules/react-native/scripts/xcode/with-environment.sh: 没有那个文件或目录 Command PhaseScriptExecution 以非零退出码失败
排查与解决步骤
修正相对路径
脚本里的../../ReactNative/node_modules/...路径存在错误:从Pods目录往上两级是项目根目录NativeReactApp,而非额外的ReactNative文件夹。正确路径应为../../node_modules/react-native/scripts/xcode/with-environment.sh。修改Xcode中的脚本配置
- 打开Xcode,找到
Pods项目下的ReactNativeDependenciestarget,进入Build Phases面板 - 定位到报错的
Script-45C7A1B4D9F210EACAF8C62608FE5A15.sh脚本,编辑第2行的路径为修正后的相对路径 - 保存配置后重新编译项目
- 打开Xcode,找到
清理并重装依赖
如果路径修正后仍报错,执行以下命令重置依赖:cd /Users/isu_412/Desktop/NativeReactApp rm -rf Pods Podfile.lock pod install npm install # 若使用yarn则执行 yarn install验证文件存在性
手动检查目标文件是否存在,执行命令:ls /Users/isu_412/Desktop/NativeReactApp/node_modules/react-native/scripts/xcode/with-environment.sh若提示文件不存在,重新安装react-native包:
npm install react-native --save # 或 yarn add react-native
内容的提问来源于stack exchange,提问作者Abinash Gadsara
相关产品推荐
相关产品推荐

