37

so I have an app built with Expo but then ejected to get ios and android folder everything works fine on both android and ios I have published it for android but on ios when I try to archive the project it gives me an error Command PhaseScriptExecution failed with nonzero exit code i don't know what's causing this error I have read a lot of StackOverflow questions tried a lot of things but with no luck here's what I tried so far.

I tried:

  • removing pod lock file, removing pod folder, doing pod deintegrate, doing pod update
    • locking and unlocking the login in keychainAccess
    • cleaning build folder in xcode
    • restarting my laptop and xcode
    • changing to legacy build system from new build system
    • removing DerivedData folder and cleaning Xcode
  • upgrading cocopods and doing pod install again

Okay so before, building with Command+B also didn't work but now i went to Targets->App name->build phases->bundle expo assets-> and checked the " run script only while installing" option and building started working but archiving still doesn't work

along with the above error i also noticed another error on xcode

enter image description here

So please if anyone has any ideas why this is happening, please?

error screenshot

28 Answers 28

91

One possible reason could be that Xcode is using an outdated version of Node (in my case, it was because I use nvm to manage my Node versions, but Xcode used an old version of Node that I had installed via HomeBrew a long time ago).

By default, Xcode will use the Node binary located at /usr/local/bin/node. Check its version by running:

/usr/local/bin/node -v
node -v

If the first command outputs an older version of Node, simply delete it and replace it with a symlink to the newer one:

rm -rf /usr/local/bin/node
ln -s $(which node) /usr/local/bin/node
Sign up to request clarification or add additional context in comments.

9 Comments

Busy updating a RN project from 0.62.3 to 0.67.1, also am running nvm for node version manager. This solved my last remaining problem. Project now builds!
I had never installed node separately (or maybe I have removed that one at some point). So there was nothing at /usr/local/bin/node. But this command fixed the issue for me ln -s $(which node) /usr/local/bin/node. Thank you
genuinely nothing worked till this. thanks! iOS16 with xcode 14 & react native 0.70.1.
Thanks a lot! I was pulling my hair with this issue. In my case, I had to add sudo to create the symlink.
Google brings me back this answer every year, and every year it saves me. I wish I could upvote it more than once. Or get a better memory.
|
13
+50

Solution 1:

it is due to Bare Expo Bundle Assets

here is the actual issue raised on forum: https://forums.expo.io/t/ios-bundle-assets-error-when-building-release-403/36616

this pull (fix) request has merged into master

-

Solution:

update your expo-cli to [email protected] or higher

npm install -g expo-cli

-

Note: Solution 1 is the answer to this question

Solution 2:

Open project directory on the terminal and run this command and archive again

react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ./ios/main.jsbundle

Solution 3:

Go to

Keychain Access -> Right-click on login -> Lock & unlock again -> Clean Xcode project ->Make build again

4 Comments

Comments are not for extended discussion; this conversation has been moved to chat.
I'm already on expo-cli version 4.4.8, so solution 1 does't work for me
This is no longer the solution. You should not be using global expo-cli
As @Jake above points out, this solution no longer helps as of 2024. I'm curious of the "stackoverflow" way to improve this. Is the OP supposed to select a new/better answer? It would be nice if there was some way to 'deprecate' a question in favor of one with more modern context. I don't know who I'm asking, just putting this out into the ether...
12

If you are using nvm, unsetting the default alias fixes the issue.

$ nvm unalias default

or if it asking to set nvm default:

$ nvm alias default node

Build the app again.

1 Comment

this worked for me (in addition to setting the link ) thanks.
12

I see in my react native app ios folder an .xcode.env.local file which points to some random temporal node path i.e. export NODE_BINARY=/var/folders/r2/hfzmqpss24zfmcc82t5fj6k80000gn/T/yarn--1712104687496-0.013929016860250165/node

I also have .xcode.env file that points to export NODE_BINARY=$(command -v node)

If I echo the value of NODE_BINARY I do see there's a correct link to node. Therefore deleting the xcode.env.local fixes the issue for me.

2 Comments

This worked exactly as described. No idea why such a weird path to Node got set in .xcode.env.local
This solution, along with another solution mentioned above, worked for me. Check the Node version, delete the .xcode.env.local file, run pod install, clean the project, and finally build it. Thank you very much!
7

My actual Error came from just above the PhaseScriptExecution part, it was due to Error: cannot find the node binary. Try setting the NODE_BINARY variable in the...

When Xcode looks for Node at /usr/local/bin/node it's not literally there, since nvm uses a more specific, dynamic path.

The solution is simple. Setup a system link based on your node path. Then try your build again. Run this in the terminal:

ln -s $(which node) /usr/local/bin/node

This answer comes from this SO answer: React Native ios build : Can't find node But is also mentioned in other answers there, and comments. This is also similar to @ashwin-m answer, but I found I didn't understand that one.

Comments

4

This issue for me was that I had the project in a directory with spaces in the name. An intermediate script that FBReactNativeSpec builds is referencing paths without escaping spaces, so it failed.

Comments

4

As per a PR comment here: https://github.com/facebook/react-native/issues/42221#issuecomment-1895955415, I needed to delete my local file .xcode.env.local and then pod install to resolve this; after updating the node versions as explained in other answers.

Comments

4

For me PhaseScriptExecution error was occurring because of hermes-engine.build. To fix I did the following:

Check in the iOS folder, if there is an .xcode.env.local file, delete it and then Clean Build Folder (Shift + cmd + k) and then Build (cmd + B) should work.

xcode .xcode.env.local file

Comments

2

unsetting the default alias fixed my issue.

$ nvm unalias default

clean the build folder then rebuild the project.

note : I'm using Xcode 14.0.1

Comments

1

Build the project with Xcode, you can see more details with the error if you scroll up. In my case it was a problem with the JS code, and not a problem natively. See my image below. JS error up top, and PhaseScriptExecution error below.

Error: Command PhaseScriptExecution failed with a nonzero exit code

If you are running from Xcode instead of react-native command line, you'll have to clean the build folder in Xcode before trying again.

Comments

1

In my case, one of the folder in the project path contained whitespace which was causing this issue.

/example folder name

I change this to

/example-folder-name

And this error did not show after that.

1 Comment

got the same issue, the folder name cannot have space! from root until projectname
0

I had the same problem as John said when I try to init a new RN project. But turns out I had to recreate the project in the path without spaces.

Comments

0

Adding this for others who may stumble across this post in search of a solution.

I tried just about every possible solution for this error and none seemed to work. In my case, it ended up being that I was using a monorepo.

If you're also using RN inside of a monorepo, a possible solution may be ensure that your RN modules are not being hoisted. RN seems to rely heavily on node_modules existing at the same level as the project; which clashes with monorepo hoisting.

If you're using Yarn, you can add the following to your package.json (the child repo where RN is used)

"workspaces": {
  "nohoist": [
    "**/*",
  ]
},

You can also exclude individual packages from being hoisted if you don't want to exclude everything, but I found that I still kept getting some variation of error until I excluded everything. With more trial and error, it's possible you don't have to exclude everything.

Comments

0

In order to fix this issue on my M1 Mac,

I had to delete all lines containing EXCLUDED_ARCHS = arm64;
in this file ios/YOUR_APP_NAME.xcodeproj/project.pbxproj

Comments

0

If you are facing this issue in 2023, please be sure to have checked the log file with the complete report.

I've found just before the "Command PhaseScriptExecution failed with a nonzero exit code" message in the report, the real problem was there.

Log files are located in the next path on macOS: /Users/your.name/Library/Developer/Xcode/DerivedData/yourprojectname-hcgvgedvowxgnneoecsorwuhwmtq/Logs/Build

Comments

0

Based on my experience with this error. There might be different solution that'll work for you as pretty much all the most voted ones actually do solve it depending on the problem you actually have going on.

I had NVM installed using Homebrew. I did hard code node path for NODE_BINARY in xcode.env and xcode.local.env but I still kept getting the error (something like that)

hermes engine Command PhaseScriptExecution failed with a nonzero exit code 

Solution: I removed flipper and it started running successfully. I had checked everything and tried other solutions but nothing else worked in my case. I ran the following command in my project directory.

NO_FLIPPER=1 bundle exec pod install --project-directory=ios

Other Tips:

  1. Make sure your whole path leading upto the directory has no spaces and special characters.
  2. If you are using NVM, then you can hard code node paths using "which node" command and set these paths in ios/.xcode.env and ios/.xcode.local.env file
  3. If you are using apple silicon, then go to node_modules/react-native/scripts/find-node-for-xcode.sh and add make adjustments in it like mentioned in other answers like hardcoding node path into PATH variable and commenting out that HOMEBREW_M1_BIN stuff.

Below is the result of my setup "npx react-native info"

System:
  OS: macOS 14.1.1
  CPU: (11) arm64 Apple M3 Pro
  Memory: 67.06 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.0
    path: ~/.nvm/versions/node/v18.19.0/bin/node
  Yarn:
    version: 1.22.21
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.3
    path: ~/.nvm/versions/node/v18.19.0/bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 15.1/15C65
    path: /usr/bin/xcodebuild
Languages:
  Java: Not Found
  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.0
    wanted: 0.73.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Comments

0

Please check your project folder name if your project name is existing black space so you face error i have resolve it.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

I had this error when my disk was simply full. Made some room and voila, works.

Comments

0

One of the common issues might be

  1. Not allowed Full disk access for Xcode. To fix this navigate to Settings -> Privacy -> Full disk access -> hit + button on the bottom -> select Xcode from Applications in side-bar

  2. Bad path to your node. To fix this navigate to /ios folder -> .xcode.env and replace export NODE_BINARY=$(command -v node) to a proper system path. Path could be something like /opt/homebrew/bin/node or /Users/bogdanyereshchenko/.nvm/versions/node/{version of node here}/bin/node. Also you can try to replace it with export NODE_BINARY=$(which node).

Comments

0

This what works for me for react native project:

In a React Native project, I encountered a build failure ("Command PhaseScriptExecution failed with a nonzero exit code") due to the /your-project/ios/.xcode.env.local file containing:

export NODE_BINARY=/var/folders/fq/asdEryEWkl/T/yarn--1987635468711-0.1543839934383647/node

Solution: Clearing the content of xcode.env.local fixed the issue. This suggests the path was incorrect or permissions were inadequate.

Recommendation: Set NODE_BINARY dynamically in your build script:

export NODE_BINARY=$(which node) 

This ensures the correct Node.js binary is used, avoiding similar build issues.

For more details check https://github.com/CocoaPods/CocoaPods/issues/12209#issuecomment-2273031216

Comments

0

I had the same error message. I missed to install a RN package via npm install. After I installed teh package the error was gone.

Comments

0

The issue was caused because somewhere in the project path, there was a space in folder name "Personal Projects". Renaming it to "PersonalProjects" resolved the issue

Comments

0

for me the problem was that I had a folder as parent of the project folder and it was called "Cross Platform" and it called it "Cross" and then said that the folder doesn't exists which was true, I changed the folder name to "CrossPlatform" without space and the build ran well

Comments

0

Relax!

Most of the time it caused bcz of Node version mismatched, the global one and the project

let me tell you an easy way, to resolve that

  • make sure you dont have multiple node managers, like nvm and normal download one
  • if you have multiple, then remove everything and install it with nvm (if you dont know nvm, search google there are plenty of that how to install)
  • set project node version globally
nvm unalias default // unset the existing
nvm alias default 20.13.1
  • check the exact version to a different terminal to make sure its done
  • create a file: xcode.env.local in path: project/ios/
  • paste this:
export NODE_BINARY=/Users/pc-name/.nvm/versions/node/v20.13.1/bin/node

** Node version should match exactly to the global one

  • quite and re-open xcode and build
  • that should resolve!

Hope that helps!

Comments

0

This caused by your xcode run node version under 19. In my case, i use nvm and the xcode did not read the node used in nvm.
To solve this, set the nvm to use node 19+ or install if not exist. run which node to get the path.

Open your xcode, go to Product > Scheme > Edit Scheme... or simply command + <.
on the Arguments tab, section Environment Variables, add new item with name NODE_BINARY and value your node 19+ path.

enter image description here

Comments

0

Delete the .xcode.env.local file once, then run pod install, and after that run the project again.

1 Comment

Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?
-1

Like Santiago's answer, I was running from a monorepo. However, the "nohoist" didn't work for me. Instead the issue had to do with the permissions of my project.

What helped me was changing the permissions of the root of the project. I did this by navigating to the parent directory of the project, then running

sudo chown -R $(whoami) ./ProjectName

That seemed to solve the issue for me.

Comments

-1
  1. Remove the “Podfile.lock file” using the command “rm -rf Podfile.lock” in the terminal.
  2. Execute the command ‘rm -rf Pods’ in the terminal to remove the entire Pods folder.
  3. Locate the “.xcworkspace” file in your project directory and delete it. Run the “pod install” command.
  4. Clean the build folder by going to “Product > Clean Build Folder” to clear any previous build artifacts and start with a clean build.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.