Skip to content

Build target hermes-engine: Command PhaseScriptExecution failed with a nonzero exit code #42221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yedi97 opened this issue Jan 10, 2024 · 47 comments

Comments

@yedi97
Copy link

yedi97 commented Jan 10, 2024

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.

image

Steps to reproduce

  1. rm -rf node_modules && rm -rf yarn.lock && yarn install
  2. cd ios && rm -rf Pods/ && rm -rf Podfile.lock && pod install
  3. 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

image

@DAMHONGDUC
Copy link

DAMHONGDUC commented Jan 10, 2024

Screenshot 2024-01-10 at 10 51 35

same here

@yedi97
Copy link
Author

yedi97 commented Jan 10, 2024

Screenshot 2024-01-10 at 10 51 35 same here

haizz, it took me more than a day but I still can't fix it, even though I tried many ways

@yedi97
Copy link
Author

yedi97 commented Jan 10, 2024

I'm resolved from #36762 (comment), thanks all!

@GunnarAK
Copy link

This issue was fixed for me by deleting ios/.xcode.env.local. Then I ran pod install and installed the app successfully on my device.

Source: #36762 (comment)

@denka9999
Copy link

@GunnarAK thanks my friend!!! It worked for me

@sparkison
Copy link

This issue was fixed for me by deleting ios/.xcode.env.local. Then I ran pod install and installed the app successfully on my device.

Source: #36762 (comment)

Also working here for a recent project upgraded to RN 0.73.6 🎉

@patras1
Copy link

patras1 commented Apr 15, 2024

Hi,
I'm still facing the issue I tried the comment below it didn't work. ( in iOS )

I also tried to disable the herms by : :hermes_enabled => false.

Any suggestions?

This issue was fixed for me by deleting ios/.xcode.env.local. Then I ran pod install and installed the app successfully on my device.

Source: #36762 (comment)

@MarlonAEC
Copy link

That' didn't work for me, still struggling with this issue. Any clue how to solve it?

@OnurVar
Copy link

OnurVar commented Apr 19, 2024

It's already mentioned in Gemfile but please make sure you're using cocoapods version is lower 1.15

@tuanngocptn
Copy link

I just fixed with issue by linking the Node to /usr/local/bin/node.
First you need to find out the real Node PATH by

command -v node # in my machine that show => /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node

Then Link that to /usr/local/bin/node.

ln -s /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node /usr/local/bin/node

Or short cut with:

ln -s $(command -v node) /usr/local/bin/node

hope that will help you.

@usamaabutt
Copy link

This issue was fixed for me by deleting ios/.xcode.env.local. Then I ran pod install and installed the app successfully on my device.

Source: #36762 (comment)

Thanks this saved me to waste more time.

@DevNvll
Copy link

DevNvll commented May 17, 2024

I had this problem when changing the node version via nvm. I was just using nvm use lts/iron
It worked when I used nvm alias default lts/iron. I also deleted the .xcode.env.local file

@christophelebris-fulll
Copy link

With react-native 0.74.2 none of the proposed fix above work

@alexlic
Copy link

alexlic commented Jul 2, 2024

Same on my end, non of the fixes mentioned above seems to work on react-native 0.74.2

@MrSolimanKing
Copy link

Same on my end, non of the fixes mentioned above seems to work on react-native 0.74.2

Have you figured out the solution, I tried all previous solutions but there is nothing worked with me with react-native 0.74.3

@johnfruit
Copy link

johnfruit commented Jul 6, 2024

Same on my end, non of the fixes mentioned above seems to work on react-native 0.74.2

Have you figured out the solution, I tried all previous solutions but there is nothing worked with me with react-native 0.74.3

same issue for me I can't build on my xcode using "react-native": "^0.74.3",

@MrSolimanKing
Copy link

I faced this issue when I upgraded my React native app from version 0.72 to 0.74.3 I tried all other solutions but nothing worked I ended up creating a new project using npx @react-native-community/cli@latest init AwesomeProject it was a hard time to copy my old project files and native side code to the new one but eventually it worked fine

@Jmzp
Copy link

Jmzp commented Jul 17, 2024

I just fixed with issue by linking the Node to /usr/local/bin/node. First you need to find out the real Node PATH by

command -v node # in my machine that show => /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node

Then Link that to /usr/local/bin/node.

ln -s /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node /usr/local/bin/node

Or short cut with:

ln -s $(command -v node) /usr/local/bin/node

hope that will help you.

This works for me!, Many thanks!

@webtamizhan
Copy link

I just fixed with issue by linking the Node to /usr/local/bin/node. First you need to find out the real Node PATH by

command -v node # in my machine that show => /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node

Then Link that to /usr/local/bin/node.

ln -s /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node /usr/local/bin/node

Or short cut with:

ln -s $(command -v node) /usr/local/bin/node

hope that will help you.

This is working

@ashuvssut
Copy link

if you are doing expo development builds, then do прх ехро prebuild --clean and try again

@djkad
Copy link

djkad commented Aug 9, 2024

I just fixed with issue by linking the Node to /usr/local/bin/node. First you need to find out the real Node PATH by

command -v node # in my machine that show => /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node

Then Link that to /usr/local/bin/node.

ln -s /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node /usr/local/bin/node

Or short cut with:

ln -s $(command -v node) /usr/local/bin/node

hope that will help you.

This is working

Life Saver. This worked for me too

@lanhuyun
Copy link

I just fixed with issue by linking the Node to /usr/local/bin/node. First you need to find out the real Node PATH by

command -v node # in my machine that show => /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node

Then Link that to /usr/local/bin/node.

ln -s /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node /usr/local/bin/node

Or short cut with:

ln -s $(command -v node) /usr/local/bin/node

hope that will help you.

Thx a lot. This worked for me. My react native version is 0.74.5.

@flacito
Copy link

flacito commented Aug 13, 2024

I just fixed with issue by linking the Node to /usr/local/bin/node. First you need to find out the real Node PATH by

command -v node # in my machine that show => /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node

Then Link that to /usr/local/bin/node.

ln -s /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node /usr/local/bin/node

Or short cut with:

ln -s $(command -v node) /usr/local/bin/node

hope that will help you.

Particularly if you are switching node versions with nvm. Thanks!

@atanu-crescentek
Copy link

I just fixed with issue by linking the Node to /usr/local/bin/node. First you need to find out the real Node PATH by

command -v node # in my machine that show => /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node

Then Link that to /usr/local/bin/node.

ln -s /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node /usr/local/bin/node

Or short cut with:

ln -s $(command -v node) /usr/local/bin/node

hope that will help you.
This helped thanks .

@vatsal1302
Copy link

I just upgrade my project to 0.70.13 to 0.75.1 . I have the same issue while upgrading. Is there any solution??

@Rodrigo816
Copy link

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/node

solved the problem for me

@jon-eubank
Copy link

jon-eubank commented Aug 21, 2024

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:

export NODE_BINARY=$(command -v node)

@christophelebris-fulll
Copy link

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

  • I installed nvm then added [[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh # This loads NVM  to the end of my ~/.zshrc
  • I uninstalled node completely from my machine
  • Then used nvm to reinstall it (node version 18), the command which node gives me /Users/username/.nvm/versions/node/v18.20.4/bin/node (which is the same result as command -v node)
  • Deleted /usr/local/bin/node
  • Relinked node with the command below
ln -s $(command -v node) /usr/local/bin/node

Side notes

I didn't delete .xcode.env.local which contains export NODE_BINARY=$(which node)

I do have the following patch for "find-node-for-xcode.sh"

diff --git a/node_modules/react-native/scripts/find-node-for-xcode.sh b/node_modules/react-native/scripts/find-node-for-xcode.sh
index a36bbc2..c7b9321 100644
--- a/node_modules/react-native/scripts/find-node-for-xcode.sh
+++ b/node_modules/react-native/scripts/find-node-for-xcode.sh
@@ -4,7 +4,7 @@
 # This source code is licensed under the MIT license found in the
 # LICENSE file in the root directory of this source tree.
 
-set -e
+set +e
 
 # WHY WE NEED THIS:
 # This script is used to find a valid instance of `node` installed in the machine.

@PulasthiAbey
Copy link

The best solution for this is to delete the ios/projectname.xcodeproj/project.pbxproj file it self and try building the project in the XCode. It sorted out the issues for me

@omar-diop
Copy link

I just fixed with issue by linking the Node to /usr/local/bin/node. First you need to find out the real Node PATH by

command -v node # in my machine that show => /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node

Then Link that to /usr/local/bin/node.

ln -s /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node /usr/local/bin/node

Or short cut with:

ln -s $(command -v node) /usr/local/bin/node

hope that will help you.

Thanks a lot! This is working with XCode 15 , nvm and react-native 0.74.5

@tenztshering
Copy link

I have resolved it by changing:
export NODE_BINARY=/opt/homebrew/bin/node
in ios > .xcode.env.local
and updating dependency packages like react, react native etc...

@saxenanickk
Copy link
Contributor

The above solution working fine when you are installing Cocoapods using pod install.
But somehow it doesn't work when you have script which takes care of pod installation. Along with some environment variables.

The issue here is it creates a .xcode.env.local with a temporary version of node. This path usually starts with /var

@thadshap
Copy link

thadshap commented Nov 15, 2024

This issue was fixed for me by deleting ios/.xcode.env.local. Then I ran pod install and installed the app successfully on my device.
Source: #36762 (comment)

Also working here for a recent project upgraded to RN 0.73.6 🎉

This really worked for me. I deleted my .xcode.env file and ran pod install, but that didn't work. Then, I also deleted .xcode.env.local and ran pod install again. Then I successfully built my project in Xcode.

@YasirNaeem25
Copy link

i solved this by adding .xcode.env.local in IOS folder
export NODE_BINARY=<static_node_path>
Screenshot 2024-12-19 at 10 39 49 AM

1-open xcode press cmd+shift+k
2- cmd+shift+b

@AmirDiafi
Copy link

I just fixed with issue by linking the Node to /usr/local/bin/node. First you need to find out the real Node PATH by

command -v node # in my machine that show => /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node

Then Link that to /usr/local/bin/node.

ln -s /Users/runner/hostedtoolcache/node/18.20.2/arm64/bin/node /usr/local/bin/node

Or short cut with:

ln -s $(command -v node) /usr/local/bin/node

hope that will help you.

That works: mac m3

@eramudeep
Copy link

facing same issue
nothing helps. tried multiple things

  1. Deleting .xcode.env.local
  2. Adding .xcode.env.local
  3. Adding static path
  4. Removing pods and reinstalling

@SGarcia710
Copy link

facing same issue nothing helps. tried multiple things

  1. Deleting .xcode.env.local
  2. Adding .xcode.env.local
  3. Adding static path
  4. Removing pods and reinstalling

Literally this made my day. Basically the node path at .xcode.env is not working and in order to avoid modifying it we can replace it with a hardcoded local route in our .xcode.env.local :)

working like charm now!

@MuhammadAmann
Copy link

This issue was fixed for me by deleting ios/.xcode.env.local. Then I ran pod install and installed the app successfully on my device.

Source: #36762 (comment)

this also worked for me, Thanks

@Ajmal0197
Copy link

Ajmal0197 commented Mar 11, 2025

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_BINARY variable in your .xcode.env file:

export NODE_BINARY=$(which node)

2. Clean Git-Ignored Files and Reinstall Dependencies

Run the following command to clean git-ignored files, remove build artifacts, and reinstall dependencies:

"cleanGitIgnoredFiles": "rm -rf .jso node_modules package-lock.json yarn.lock && cd ios && rm -rf build pods .xcode.env.local Podfile.lock && cd .. && cd android && rm -rf build && cd app && rm -rf build && cd .. && cd .. && yarn installAll",
"installAll": "yarn install && cd ios && pod install && cd .."

This script will:

  • Remove all unnecessary files and dependencies.
  • Clean the iOS, Android, and app build directories.
  • Reinstall all required dependencies with yarn install and pod install.

3. Delete .xcode.env.local (if needed)

If the issue persists, try deleting the .xcode.env.local file, as it may contain outdated or conflicting environment variables:

rm -rf .xcode.env.local

@mikemilla
Copy link

This issue was fixed for me by deleting ios/.xcode.env.local. Then I ran pod install and installed the app successfully on my device.
Source: #36762 (comment)

this also worked for me, Thanks

This works for me as well. My xcode env local file was using node 18 and my machine was using 22.

@kjgetcarnera
Copy link

Solution That Worked for Me:
The problem was caused by a stale .xcode.env.local file that pointed to a removed Node.js version.

Steps to Fix:
Delete the .xcode.env.local file:

rm ~/.xcode.env.local
Reinstall dependencies and clean the project:

cd ios
rm -rf Pods Podfile.lock
pod install
cd ..
Clean and rebuild the project:

npx react-native run-ios

Why This Works:
.xcode.env.local stores environment variables and can contain outdated paths for Node.js after an upgrade.
Deleting it allows Xcode to use the correct Node.js path.

@gayanrathnayaka
Copy link

None of the suggested solutions works for me

Xcode version 16.3
React Native Version 0.79.1

@fadhildwia
Copy link

please for
Xcode version 16.3
React native version 0.72.7

@Buddhaa97
Copy link

As mentioned above, export NODE_BINARY=<static_node_path> worked. Although I already had the static path, I was still encountering this issue. I later noticed that my path was not wrapped in double quotes (""), and adding them resolved the problem.
export NODE_BINARY="/Users/xx/.nvm/versions/node/xx.xx.x/bin/node"

@carlgrob5171989
Copy link

None of the suggested solutions works for me

Xcode version 16.2 React Native Version 0.79.1

Did you resolve the issue?

@devShrutiNagani
Copy link

post_install do |installer|
react_native_post_install(installer)

installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
end
end
end

----> Add this post_install block at the bottom of the Podfile

@gayanrathnayaka
Copy link

None of the suggested solutions works for me
Xcode version 16.2 React Native Version 0.79.1

Did you resolve the issue?

In my case, the problem was due to an incorrect REACT_NATIVE_PATH. The error message pointed to a specific script—when I opened that script in my editor, I saw it was trying to reference REACT_NATIVE_PATH, but the path it was using didn’t exist.

To fix it, I defined the correct REACT_NATIVE_PATH as a user environment variable. Once I did that, the issue was resolved.

Carefully read the full error message it usually mentions the script where the error originates. Open that script to investigate further; it often provides valuable clues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests