49

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.

0

17 Answers 17

79

For me anyone of this solutions work because, with Xcode 14.2 and RN0.70.5, there is the following 2 files in ios folder which fixe node version with the path (I don't know since which version and which one adds this files) :

  1. .xcode.env
  2. .xcode.env.local

If you are this files inside ios folder just do this (with or without nvm) :

which node

And put the patch inside the .xcode.env.local like this :

export NODE_BINARY="/Users/Blabla/.nvm/versions/node/v16.14.0/bin/node"

If this files doesn't exist, try to add it and maybe Xcode will take it into account :

Inside ios/.xcode.env

# This `.xcode.env` file is versioned and is used to source the environment
# used when running script phases inside Xcode.
# To customize your local environment, you can create an `.xcode.env.local`
# file that is not versioned.

# NODE_BINARY variable contains the PATH to the node executable.
#
# Customize the NODE_BINARY variable here.
# For example, to use nvm with brew, add the following line
# . "$(brew --prefix nvm)/nvm.sh" --no-use
export NODE_BINARY=$(command -v node)

Inside ios/.xcode.env.local

export NODE_BINARY="/Users/Blabla/.nvm/versions/node/v16.14.0/bin/node"
Sign up to request clarification or add additional context in comments.

2 Comments

RN has a section about finding out why something failed now reactnative.dev/docs/… not finding node was the cause for me, but I've used this fix instead stackoverflow.com/a/50419734/4777865
I used export NODE_BINARY="/opt/homebrew/bin/node" to .xcode.env.local. And it is fixed.
21

If you shut down your computer or did a recent upgrade to node or nvm something in the cache folder gets reset and the build fails. The code in the react native node_modules/react-native/scripts/find-node.sh script related to nvm. Following this advice: https://stackoverflow.com/a/70104375/5927929 worked for me with a small change.

My specs: Mac intel chip RN 0.68.2 nvm (0.33.11) && node (v18.3.0) install

Steps:

  1. nvm unalias default
  2. nvm alias default node
  3. Build in xcode...done

2 Comments

nvm maintainer here: nvm is definitely not to blame whatsoever. All it does is automate node's own install process.
This helped me - I unaliased default (which was linked to an nvm controlled v18) and re-aliased to "system". It is much happier now!
16

Took me ages to figure this out, my problem was unrelated to any of the other answers.

The issue was that my project's full path contained an empty space, so turning

/Users/radu/Projects/midi control/ua/UaRemoteControl

into

/Users/radu/Projects/midi-control/ua/UaRemoteControl

fixed the build error in XCode.

2 Comments

where to find this path?
you can find the path. just check the directory path to your react-native project. if there are any empty spaces like /react native/my-app, remove the space and run the project again
7

For me, the issue was due to space in folder name.

I had the problem when the name of the parent folder was 'Personal Development'. I have changed it to 'PersonalDevelopment' and the problem has vanished.

1 Comment

I've been searching for this issue and literally I'm pissed off then I just try your solution and it WORKS!! can anyone let me know why it is like that?? its this a issue with Xcode or what?
6

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

5 Comments

Not working for me. As well as I am not using nvm
I upgraded my nodejs version to 16.14.0 and it worked. i think problem in version nodejs
This is working. Check your current node version in lib folder and just add here. finally i found the solution. Thanks.
My code space does not look like the one shown, I do not have export anywhere in it, just these lines...set -e WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh" REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
It didn't work for me. I've tried do that in several ways.
2

In my case this error raising due to node path is not set in PATH Variables. Try to run below command it will set missing node path in PATH variable and it resolve the error.

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

https://reactnative.dev/docs/new-architecture-troubleshooting#:~:text=Command%20PhaseScriptExecution%20failed%20with%20a,libraries%20(FBReactNativeSpec%2C%20rncore).

1 Comment

I used homebrew to install node@20 and this was the only thing that helped.
2

Fixed this by updating node_modules/react-native/scripts/find-node.sh at line # 7.

set -e
 
to

set +e

Comments

2

In my case:

  • M1 chip
  • MacOS Ventura 13.3.1
  • Xcode Version 13.4
  • node v14.18.1

I had node & npm installed in 2 places - 1 with brew and another with nvm.

You can check by using these commands

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

If the above 2 give 2 different versions, Your issue also could be the same.

I removed the ones in the /usr/local/bin

rm -rf /usr/local/bin/node
rm -rf /usr/local/bin/npm

Installed v14.18.1 again in nvm

nvm use v20.1.0
nvm uninstall node 14.18.1
nvm install node 14.18.1
nvm use v14.18.1

Removed all unused versions from nvm

nvm uninstall node 20.1.0

Then symlinked node from nvm to bin

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

then cleaned the DerivedData folder

rm -rf ~/Library/Developer/Xcode/DerivedData/* && rm -rf ~/Library/Caches/org.swift.swiftpm

Then cleaned builds from Xcode and built again

Comments

1

Simply delete the FBReactNativeSpec file from the Pods as shown in the image below.enter image description here

Comments

0

Ok, worth trying this.

2 different solutions :

1: As soon as we get this error message:

Always scroll up & read the issue if written in that log file. Any issues like syntax error or issue related to your js code (like multiple imports in your js files or if you had forgot to import something). If yes, you can fix that first & re build it.

In my case I had multiple imports of one of the RN components.

if not

2: got to 'Keychain access' in your mac, lock & unlock login and re build it, this may help you.

And make sure to 'cd ios' && 'pod install' if you have forgot to do it after installing any of the npm package.

Comments

0

In my case, with Node.js version 16.20.2 installed on my macOS Sonoma 14.1 using the DMG file, when I attempted to execute nvm alias default node, I encountered the following error message:

! WARNING: Version 'node' does not exist.

To resolve this issue, I followed these steps:

  1. Reinstalled Node.js version 16.20.2 using the following command:

nvm install 16.20.2

  1. Subsequently, I set the "default" alias using the complete version number, rather than "node," with the following command:

nvm alias default 16.20.2

It's worth noting that I'm using Xcode 15.0.1.

Comments

0

The issue for me was the newest Apple Developer Program License Agreement was not accepted by the owner of my Apple account. So it wasn't creating any ad hoc provisioning profiles until my boss accepted it.

tl;dr - sign in to developer.apple.com and make sure to accept the agreement.

Comments

0

In node_modules/react-native/scripts/find-node.sh, do

change line no 7 set -e. ==> set +e

Comments

-1

In case someone else tried everything mentioned here and in other threads, and it didn't work, here is what worked for me!

[!] CocoaPods could not find compatible versions for pod "hermes-engine": In snapshot (Podfile.lock): hermes-engine (from ../node_modules/react-native/sdks/hermes/hermes-engine.podspec) In Podfile: hermes-engine (from ../node_modules/react-native/sdks/hermes/hermes-engine.podspec) It seems like you've changed the version of the dependency hermes-engine and it differs from the version stored in Pods/Local Podspecs. You should run pod update hermes-engine --no-repo-update to apply changes made locally.

But instead of running the command they gave me, I deleted Podfile.lock and the Pods directory, then reran pod install, and the build finally worked!

Comments

-1
  1. Determine where your node binary is:
    $ which node
    /opt/homebrew/bin/node
  1. Add a fixer function in your Podfile:
    def fix_fb_react_native_spec(installer)
      installer.pods_project.targets.each do |target|
        if target.name == 'FBReactNativeSpec'
          target.build_configurations.each do |config|
            if config.name == 'Debug' or config.name == 'Release'
              config.build_settings['NODE_BINARY'] = '/opt/homebrew/bin/node'
            end
          end
        end
      end
    end
  1. In your postinstall, add fix_fb_react_native_spec(installer) like so:
     post_install do |installer|
        react_native_post_install(installer)
        fix_fb_react_native_spec(installer)
      end
  1. Pod install

  2. Rebuild (ideally with a clean build)

Comments

-4

In my case:

  • M1 chip
  • MacOS Monterey
  • Xcode Version 13.2.1
  • node v16.6.0
  • react-native 0.69

I was trying to build the iOS app via terminal under Rossetta. Once I tried to use native M1 terminal - it worked well.

Go to your applications, right click on the app, get info, check OFF Open using Rossetta

enter image description here

Comments

-10

just run this command

brew uninstall nvm

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.