react-native: React Native's initial project doesn't run on IOS.
Description
I created a new project using the command npx react-native init MyApp --template react-native-template-typescript
.
When i run npx react-native run-ios
, it gives me below error.
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/macbookpro/Library/Developer/Xcode/DerivedData/MyApp-gvadqhjqjqogdegfwqsahxwqnkps/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-8C01FEA837F8EC37C13D05D97D3F6C1B.sh
(1 failure)
React Native version:
System: OS: macOS 11.2.3 CPU: (4) x64 Intel® Core™ i5-7360U CPU @ 2.30GHz Memory: 58.32 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.16.0 - /usr/local/bin/node Yarn: Not Found npm: 6.14.11 - /usr/local/bin/npm Watchman: Not Found Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 Android SDK: Not Found IDEs: Android Studio: 4.0 AI-193.6911.18.40.6514223 Xcode: 12.4/12D4e - /usr/bin/xcodebuild Languages: Java: 14.0.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.1 => 17.0.1 react-native: 0.64.0 => 0.64.0 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 14
- Comments: 43 (2 by maintainers)
Removing
from
~/.bash_profile
.AND
Commenting out all the code from
project/node_modules/react-native/scripts/find-node.sh
helped to solve this issue.I am facing the same issue with
yarn ios
but if I build the app from Xcode it works.@sumanbhattarai Why did you close this issue, I know that disabling NVM and removing code from find-node.sh resolves it, but then there must be a bug in find-node.sh which is under the control of the react-native project.
It seems that some effort is going on in react-native to support also NVM, so this bug must be fixed, right? Or is it resolved in another issue?
@imkrunal no luck. Building the app from Xcode gives me the same error.
@hlynbech okay, i have reopened it.
I had the same issue, problem details are clear in the XCode:
and it seems the problem in the script is here:

Try to fix the nvm on your computer, as commenting out the node_modules makes no sense. Usually, the problem itself is the nvm, so try to check if the nvm has node and set the default alias:
Try:
nvm alias default node
Or install the node by nvm first:
Make sure you don’t have space in the folder names. Check this comment.
https://github.com/facebook/react-native/issues/31259#issuecomment-808899927
I know there seem to be some solutions here but none worked for me. The solution that ended up working was really simple. Go through the absolute path of your project, and make sure there are no spaces! I had to edit a file in a directory 3 parents prior to my app folder.
For me it was something like “users/…/Desktop/school/class abc/test/project” <- I had to make it ‘class-abc’
I solved this by using fnm instead of nvm
Try removing the spaces on the project path and run it
Eg. React Native Projects/yourproject to ReactNativeProjects/yourproject
It resolved the problem for me
This patch got things working for me with
nodenv
on macOS 11.3.1 with Xcode 12.5This is specific to
nodenv
mostly, but I added a bunch of logging tofind-node.sh
. Without the--no-rehash
flag,nodenv
apparently attemps torehash
when the command is evaluated.I didn’t look into all the details, but this seemed to be the ultimate error.
Here’s my full (more or less) Build Phases log for
[CP-User] Generate Specs
.Actually, this helps to make this stuff work but there is definitely an issue with
nvm
along with the exported env variables in the iOS build phase, espacially thePATH
which makes thecommand which node
differs from you login environnment, and therefore makesnvm
raise an error in the build.I finally decided to do the same as @sumanbhattarai and rely on
nodenv
to make it work.Is there someone aware of how the environment variables are set by Xcode for the build phases and how to customize/fix it ?
We had the same issue when building on a build server with fastlane, when fastlane is started from a shell that has NVM environment variables set. Removing the NVM variables as @sumanbhattarai suggests from the shell (in this case in .zshrc) makes the build work in fastlane. The build never had issues when building from the Xcode UI.
@mineturtle2137 's solution solved it for me, thank you so much man!! 🙏 🙏 🙏 🙏 🙏 🎉 🎉 🎉
I had the same problem, but I fixed it using
nvm Install v16.10.0
I am on react 0.67.2 (new project) I tried on two different machines with this issue. Only @sumanbhattarai solution works.
Thanks this works for me
I ONLY commented out
project/node_modules/react-native/scripts/find-node.sh
like @sumanbhattarai mentioned as the second part of his solution above. I’m still scared of bash a bit so I didn’t dig in to mess with my paths.Think this will cause me headaches in the future? hopefully, a true fix and less of a patch will be coming soon.
(edit 5/20/21 - broke again - going to try other solutions from above and below 😂 )