FITURE

If you can fight, fight.

首页 >> 分享>>“Command PhaseScriptExecution failed with a nonzero exit code” XCode 构建iOS包 – React Native 开发避坑记录

“Command PhaseScriptExecution failed with a nonzero exit code” XCode 构建iOS包 – React Native 开发避坑记录

Posted by fiture / 2025年02月27日 / 分享

React Native 开发构建iOS应用包时,XCode 构建报错,如图所示:

没有任何可用信息,只有一句这样的话:hermes-engine 报错,让人摸不着头脑,不知道是哪里出了问题。

  • Command PhaseScriptExecution failed with a nonzero exit code 接下来点开详细日志,发现是 hermes-engine 另外的警告:
  • Run script build phase '[CP-User] [Hermes] Replace Hermes for the right configuration, if needed' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase.

信息很有限,无从下手,这时候只有去网上搜索了,找到问题原因,原来是 ios/.xcode.env.local 文件中配置了 错误的 NODE_BINARY 变量,导致构建失败。

我打开 ios/.xcode.env.local 文件,发现配置如下:

# export NODE_BINARY=/var/folders/x0/0cgks_l11tj_j2ymh96ztkq40000gn/T/yarn--1739163053497-0.8478783184910024/node

再去终端执行 /var/folders/x0/0cgks_l11tj_j2ymh96ztkq40000gn/T/yarn--1739163053497-0.8478783184910024/node 发现这个配置是错误的,导致构建失败。

所以大概率是这个配置问题,解决方法有:

  • 删除 ios/.xcode.env.local、执行 pod install 重新安装依赖。
  • 或者将.xcode.env.local文件中的 NODE_BINARY 配置,改为正确的 node 路径,使用which node命令获取。

总结遇到这种错误可以先看日志信息,如果和 hermes-engine 相关,可以先检查 ios/.xcode.env.local 文件中的 NODE_BINARY 配置,是否正确。

看到这位老兄报错还挺清晰的,不知道为什么我的XCode 15 不报具体错误,晕死:

参考链接:

发表评论

电子邮件地址不会被公开。 必填项已用*标注