Search code examples
iosxcodereact-nativeterminalapple-m1

React Native - FBReactNativeSpec Command PhaseScriptExecution failed with a nonzero exit code


I am using a MacBook Pro with

  • M1 chip
  • MacOS Big Sur
  • Xcode Version 13.2.1
  • node v14.17.5

I wanted to follow this tutorial to set up a new React Native project called AwesomeProject https://reactnative.dev/docs/environment-setup the section with React Native CLI Quickstart.

When I try to run the app in terminal by typing: npx react-native run-ios my build fails with the following error:

PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/thomashuber/Library/Developer/Xcode/DerivedData/AwesomeProject-aprperxvqrezbfeyvousbagyesvr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-5F4C70EF7D90A5A5BDAEB404279F232A.sh (in target 'FBReactNativeSpec' from project 'Pods') (1 failure)

When I try to run it in Xcode either on a simulator or on an iPhone device I get the following error in FBReactNativeSpec:

Command PhaseScriptExecution failed with a nonzero exit code

I run it with

/bin/sh -c /Users/thomashuber/Library/Developer/Xcode/DerivedData/AwesomeProject-aprperxvqrezbfeyvousbagyesvr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-5F4C70EF7D90A5A5BDAEB404279F232A.sh

I restarted my MacBook, I deleted the project and tried it again. I cleaned the project in Xcode but none of it helps. I suspect that it is due the M1 chip of my MacBook.


Solution

  • I managed to get rid of the FBReactNativeSpec error by editing the Project settings.

    Try the following:

    1. In Xcode select your app's project and then select the target.

    2. In Terminal enter the following command to find out the path of your node installation:

    which node

    This should give you a path. Something like:

    /Users/thomashuber/.nvm/versions/node/v16.14.0/bin/node

    1. Copy this path.

    2. In Xcode with the target selected click on Build Phases and open Bundle React Native code and images

    3. Replace NODE_BINARY=node. Instead of node enter the path that you have copied so that it is something like this NODE_BINARY=/Users/thomashuber/.nvm/versions/node/v16.14.0/bin/node

    Replacing node with node path