react-native: Build target hermes-engine: Command PhaseScriptExecution failed with a nonzero exit code
Description
I am facing the following problem after running my project again, the pod installed successfully without any problem, but when running using yarn run ios command, the error as below occurs, has anyone encountered this? like me? please help me. Yesterday I ran React Native version 0.73.1 and it still worked fine. Today, when I upgraded to 0.73.2, the following problem occurred. I also downgraded back to 0.73.1 but still no luck.
Steps to reproduce
- rm -rf node_modules && rm -rf yarn.lock && yarn install
- cd ios && rm -rf Pods/ && rm -rf Podfile.lock && pod install
- cd … && yarn ios
React Native Version
0.73.2
Affected Platforms
Runtime - iOS, Build - MacOS
Output of npx react-native info
System:
OS: macOS 14.2.1
CPU: (8) arm64 Apple M1
Memory: 476.27 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 20.8.1
path: /opt/homebrew/bin/node
Yarn:
version: 1.22.21
path: /opt/homebrew/bin/yarn
npm:
version: 10.1.0
path: /opt/homebrew/bin/npm
Watchman: Not Found
Managers:
CocoaPods:
version: 1.13.0
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.2
- iOS 17.2
- macOS 14.2
- tvOS 17.2
- visionOS 1.0
- watchOS 10.2
Android SDK:
Android NDK: 22.1.7171670
IDEs:
Android Studio: 2023.1 AI-231.9392.1.2311.11255304
Xcode:
version: 15.2/15C500b
path: /usr/bin/xcodebuild
Languages:
Java:
version: 18.0.2
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: ^18.2.0
react-native:
installed: 0.73.2
wanted: ^0.73.2
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: false
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false
Stacktrace or Logs
Build target hermes-engine of project Pods with configuration Release
warning: 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. (in target 'hermes-engine' from project 'Pods')
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.
PhaseScriptExecution [CP-User]\ [Hermes]\ Replace\ Hermes\ for\ the\ right\ configuration,\ if\ needed /Library/Developer/Xcode/DerivedData/myProjectName-gzdlehmipieiindfjyfrhhcjupam/Build/Intermediates.noindex/ArchiveIntermediates/myProjectName/IntermediateBuildFilesPath/Pods.build/Release-iphoneos/hermes-engine.build/Script-46EB2E0002C950.sh (in target 'hermes-engine' from project 'Pods')
Node found at: /var/folders/d5/f1gffcfx27ngwvmw8v8jdm7m0000gn/T/yarn--1704767526546-0.12516067745295967/node
/Library/Developer/Xcode/DerivedData/myProjectName-gzdlehmipieiindfjyfrhhcjupam/Build/Intermediates.noindex/ArchiveIntermediates/myProjectName/IntermediateBuildFilesPath/Pods.build/Release-iphoneos/hermes-engine.build/Script-46EB2E0002C950.sh: line 9: /var/folders/d5/f1gffcfx27ngwvmw8v8jdm7m0000gn/T/yarn--1704767526546-0.12516067745295967/node: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code
Reproducer
https://github.com/yedi97/reproducer-react-native
Screenshots and Videos
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 47 (1 by maintainers)
This issue was fixed for me by deleting
ios/.xcode.env.local. Then I ranpod installand installed the app successfully on my device.Source: https://github.com/facebook/react-native/issues/36762#issuecomment-1782525316
same here
I just fixed with issue by linking the Node to
/usr/local/bin/node. First you need to find out the real Node PATH byThen Link that to
/usr/local/bin/node.Or short cut with:
hope that will help you.
I’m resolved from https://github.com/facebook/react-native/issues/36762#issuecomment-1755400555, thanks all!
Thanks this saved me to waste more time.
With react-native 0.74.2 none of the proposed fix above work
this also worked for me, Thanks
Same on my end, non of the fixes mentioned above seems to work on react-native 0.74.2
The best solution for this is to delete the
ios/projectname.xcodeproj/project.pbxprojfile it self and try building the project in the XCode. It sorted out the issues for meAlso working here for a recent project upgraded to RN 0.73.6 🎉
I faced this issue when I upgraded my React native app from version
0.72to0.74.3I tried all other solutions but nothing worked I ended up creating a new project usingnpx @react-native-community/cli@latest init AwesomeProjectit was a hard time to copy my old project files and native side code to the new one but eventually it worked fineThis is working
To resolve the “Build target hermes-engine: Command PhaseScriptExecution failed with a nonzero exit code” error, you can try the following steps:
1. Set Correct NODE_BINARY Path
Make sure the correct Node.js binary is being used by setting the
NODE_BINARYvariable in your.xcode.envfile:2. Clean Git-Ignored Files and Reinstall Dependencies
Run the following command to clean git-ignored files, remove build artifacts, and reinstall dependencies:
This script will:
yarn installandpod install.3. Delete .xcode.env.local (if needed)
If the issue persists, try deleting the
.xcode.env.localfile, as it may contain outdated or conflicting environment variables:facing same issue nothing helps. tried multiple things
i solved this by adding .xcode.env.local in IOS folder export NODE_BINARY=<static_node_path>
1-open xcode press cmd+shift+k 2- cmd+shift+b
This works for me!, Many thanks!
None of the suggested solutions works for me
Xcode version 16.3 React Native Version 0.79.1
That works: mac m3
Finally found the solution for RN 0.74.5 (might work for any version starting from 0.73). For those like me who tried the solutions above, the missing piece of the puzzle could be the node install cleaning.
Clean node install
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh # This loads NVMto the end of my~/.zshrcwhich nodegives me/Users/username/.nvm/versions/node/v18.20.4/bin/node(which is the same result ascommand -v node)/usr/local/bin/nodeSide notes
I didn’t delete
.xcode.env.localwhich containsexport NODE_BINARY=$(which node)I do have the following patch for “find-node-for-xcode.sh”
In my case (RN 0.73.9) when I ran “pod install” it was automatically generating the .xcode.env.local if it didn’t already exist. The NODE_BINARY it was setting in that file was set to a location of node, but it wasn’t the same as the location that appeared when I would run “which node”.
After replacing the default NODE_BINARY location with the path from “which node” everything worked correctly. Subsequent runs of “pod install” don’t overwrite the change either which is nice.
For my set-up, I’m using NVM as my node manager. Also .xcode.env (note: NOT the local one) is just set to:
In my case on .xcode.env I changed to this
export NODE_BINARY="/usr/local/bin/node"and run the command
ln -s $(command -v node) /usr/local/bin/nodesolved the problem for me
Particularly if you are switching node versions with nvm. Thanks!
I had this problem when changing the node version via nvm. I was just using
nvm use lts/ironIt worked when I usednvm alias default lts/iron. I also deleted the .xcode.env.local file