I am using a MacBook Pro with
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 :
/bin/sh -c /Users/thomashuber/Library/Developer/Xcode/DerivedData/AwesomeProject-aprperxvqrezbfeyvousbagyesvr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-5F4C70EF7D90A5A5BDAEB404279F232A.sh
Command PhaseScriptExecution failed with a nonzero exit code
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.
I managed to get rid of the FBReactNativeSpec error by editing the Project settings.
Try the following:
In Xcode select your app's project and then select the target.
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
Copy this path.
In Xcode with the target selected click on Build Phases and open Bundle React Native code and images
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
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):
.xcode.env
.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"
It seems like nvm is messing with the build process and 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. Nvm is the culprit and the code surrounding it 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:
nvm unalias default
nvm alias default node
Simply delete the FBReactNativeSpec file from the Pods as shown in the image below. enter image description here
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.
Determine what your node binary is:
$ which node /opt/homebrew/bin/node
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
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
Pod install
Rebuild (ideally with a clean build)
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
In case someone else tried everything mentioned here and in other threads, and it didn't work, here is what worked for me!
pod install
and got this error message:[:] 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 dependencyhermes-engine
and it differs from the version stored inPods/Local Podspecs
. You should runpod 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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.