22

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

Surafel
  • 675
  • 4
  • 11
  • 24

12 Answers12

55

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
glocore
  • 1,727
  • 1
  • 14
  • 24
10

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 expo-cli@3.19.2 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

Muhammad Numan
  • 23,222
  • 6
  • 63
  • 80
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/215713/discussion-on-answer-by-muhammad-numan-command-phasescriptexecution-failed-with). – Samuel Liew Jun 11 '20 at 03:33
  • I'm already on expo-cli version 4.4.8, so solution 1 does't work for me – SeanMC Jul 08 '21 at 13:58
8

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.

Kumar Parth
  • 439
  • 5
  • 7
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.

SeanMC
  • 1,960
  • 1
  • 22
  • 33
1

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.

John Scalo
  • 3,194
  • 1
  • 27
  • 35
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.

David
  • 151
  • 1
  • 5
1

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

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.

Zk_Fang08
  • 1
  • 1
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.

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

Vlad R
  • 1,851
  • 15
  • 13
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

-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.