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

无法获取同路径下已存在文件的路径,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中的脚本配置

    1. 打开Xcode,找到Pods项目下的ReactNativeDependencies target,进入Build Phases面板
    2. 定位到报错的Script-45C7A1B4D9F210EACAF8C62608FE5A15.sh脚本,编辑第2行的路径为修正后的相对路径
    3. 保存配置后重新编译项目
  • 清理并重装依赖
    如果路径修正后仍报错,执行以下命令重置依赖:

    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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.02 06:04:54