12

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
  • 485
  • 1
  • 8
  • 21

8 Answers8

22

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,244
  • 1
  • 11
  • 23
8

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
  • 17,689
  • 4
  • 42
  • 65
  • 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
2

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
  • 309
  • 3
  • 6
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,010
  • 1
  • 25
  • 33
1

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,395
  • 1
  • 14
  • 29
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
  • 91
  • 4
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.