Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New project not working on IOS Xcode 12.4 react-native 0.64 (Command PhaseScriptExecution failed with a nonzero exit code) #31181

Closed
javierdac opened this issue Mar 17, 2021 · 93 comments
Labels
Needs: Triage 🔍 Resolution: Locked This issue was locked by the bot.

Comments

@javierdac
Copy link

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

i try to create a new project (npx react-native init TestApp --version 0.64.0 --template react-native-template-typescript). It fails with XCode 12.4

React Native version:

System:
OS: macOS 10.15.7
CPU: (8) x64 Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz
Memory: 78.82 MB / 16.00 GB
Shell: 3.1.2 - /usr/local/bin/fish
Binaries:
Node: 14.13.1 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.8 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
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:
API Levels: 23, 28, 29
Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3
System Images: android-30 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.1 AI-201.8743.12.41.6953283
Xcode: 12.4/12D4e - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_265 - /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

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. npx react-native init TestProject
  2. npm i && cd ios && pod install && cd.. && npm run ios

Expected Results

Run the base app

Snack, code example, screenshot, or link to a repository:

Captura de Pantalla 2021-03-17 a la(s) 17 58 34

Error: Command PhaseScriptExecution failed with a nonzero exit code

@AutoFt
Copy link

AutoFt commented Mar 18, 2021

I have the same problem.

This is my configuration information.

System:
OS: macOS 11.2.3
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 3.76 GB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.15.4 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.10 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
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: Not Found
Xcode: 12.4/12D4e - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_281 - /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

@mohdabbas
Copy link

Same issue for me as well!!! Any solutions?? I tried https://dev.to/glocore/react-native-command-phasescriptexecution-failed-of9, but no success!

@rochapablo
Copy link

rochapablo commented Mar 18, 2021

I'm also having trouble to start a new RN project. I've already tried to add a dummy.swift and do the Bridging Header Thing, but still not working.

ld: warning: Could not find or use auto-linked library 'swiftFoundation'
ld: warning: Could not find or use auto-linked library 'swiftDarwin'
ld: warning: Could not find or use auto-linked library 'swiftUIKit'
ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation'
ld: warning: Could not find or use auto-linked library 'swiftQuartzCore'
ld: warning: Could not find or use auto-linked library 'swiftCore'
ld: warning: Could not find or use auto-linked library 'swiftCoreGraphics'
ld: warning: Could not find or use auto-linked library 'swiftObjectiveC'
ld: warning: Could not find or use auto-linked library 'swiftDispatch'
ld: warning: Could not find or use auto-linked library 'swiftSwiftOnoneSupport'
ld: warning: Could not find or use auto-linked library 'swiftCoreImage'
ld: warning: Could not find or use auto-linked library 'swiftMetal'
Undefined symbols for architecture arm64:
  "protocol descriptor for Swift.ExpressibleByFloatLiteral", referenced from:
      l_got.$ss25ExpressibleByFloatLiteralMp in libYogaKit.a(YGLayoutExtensions.o)
  "associated type descriptor for Swift.ExpressibleByIntegerLiteral.IntegerLiteralType", referenced from:
      l_got.$s18IntegerLiteralTypes013ExpressibleByaB0PTl in libYogaKit.a(YGLayoutExtensions.o)
  "associated conformance descriptor for Swift.ExpressibleByIntegerLiteral.Swift.ExpressibleByIntegerLiteral.IntegerLiteralType: Swift._ExpressibleByBuiltinIntegerLiteral", referenced from:
      l_got.$ss27ExpressibleByIntegerLiteralP0cD4TypeAB_s01_ab7BuiltincD0Tn in libYogaKit.a(YGLayoutExtensions.o)
  "method descriptor for Swift.ExpressibleByFloatLiteral.init(floatLiteral: A.FloatLiteralType) -> A", referenced from:
      l_got.$ss25ExpressibleByFloatLiteralP05floatD0x0cD4TypeQz_tcfCTq in libYogaKit.a(YGLayoutExtensions.o)
  "protocol descriptor for Swift.ExpressibleByIntegerLiteral", referenced from:
      l_got.$ss27ExpressibleByIntegerLiteralMp in libYogaKit.a(YGLayoutExtensions.o)
  "value witness table for Builtin.Int32", referenced from:
      full type metadata for __C.YGUnit in libYogaKit.a(YGLayoutExtensions.o)
  "__swift_FORCE_LOAD_$_swiftCoreImage", referenced from:
      __swift_FORCE_LOAD_$_swiftCoreImage_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftCoreImage_$_YogaKit)
  "protocol witness table for Swift.Float : Swift._ExpressibleByBuiltinFloatLiteral in Swift", referenced from:
      associated type witness table accessor for Swift.ExpressibleByFloatLiteral.FloatLiteralType : Swift._ExpressibleByBuiltinFloatLiteral in __C.YGValue : Swift.ExpressibleByFloatLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "__swift_FORCE_LOAD_$_swiftFoundation", referenced from:
      __swift_FORCE_LOAD_$_swiftFoundation_$_rn64ts in dummy.o
      __swift_FORCE_LOAD_$_swiftFoundation_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftFoundation_$_rn64ts, __swift_FORCE_LOAD_$_swiftFoundation_$_YogaKit )
  "_swift_getForeignTypeMetadata", referenced from:
      type metadata accessor for __C.YGValue in libYogaKit.a(YGLayoutExtensions.o)
      type metadata accessor for __C.YGUnit in libYogaKit.a(YGLayoutExtensions.o)
  "__swift_FORCE_LOAD_$_swiftObjectiveC", referenced from:
      __swift_FORCE_LOAD_$_swiftObjectiveC_$_rn64ts in dummy.o
      __swift_FORCE_LOAD_$_swiftObjectiveC_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftObjectiveC_$_rn64ts, __swift_FORCE_LOAD_$_swiftObjectiveC_$_YogaKit )
  "protocol witness table for Swift.Int : Swift._ExpressibleByBuiltinIntegerLiteral in Swift", referenced from:
      associated type witness table accessor for Swift.ExpressibleByIntegerLiteral.IntegerLiteralType : Swift._ExpressibleByBuiltinIntegerLiteral in __C.YGValue : Swift.ExpressibleByIntegerLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "method descriptor for Swift.ExpressibleByIntegerLiteral.init(integerLiteral: A.IntegerLiteralType) -> A", referenced from:
      l_got.$ss27ExpressibleByIntegerLiteralP07integerD0x0cD4TypeQz_tcfCTq in libYogaKit.a(YGLayoutExtensions.o)
  "__swift_FORCE_LOAD_$_swiftCoreFoundation", referenced from:
      __swift_FORCE_LOAD_$_swiftCoreFoundation_$_rn64ts in dummy.o
      __swift_FORCE_LOAD_$_swiftCoreFoundation_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftCoreFoundation_$_YogaKit, __swift_FORCE_LOAD_$_swiftCoreFoundation_$_rn64ts )
  "associated type descriptor for Swift.ExpressibleByFloatLiteral.FloatLiteralType", referenced from:
      l_got.$s16FloatLiteralTypes013ExpressibleByaB0PTl in libYogaKit.a(YGLayoutExtensions.o)
  "__swift_FORCE_LOAD_$_swiftQuartzCore", referenced from:
      __swift_FORCE_LOAD_$_swiftQuartzCore_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftQuartzCore_$_YogaKit)
  "__swift_FORCE_LOAD_$_swiftDispatch", referenced from:
      __swift_FORCE_LOAD_$_swiftDispatch_$_rn64ts in dummy.o
      __swift_FORCE_LOAD_$_swiftDispatch_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftDispatch_$_YogaKit, __swift_FORCE_LOAD_$_swiftDispatch_$_rn64ts )
  "associated conformance descriptor for Swift.ExpressibleByFloatLiteral.Swift.ExpressibleByFloatLiteral.FloatLiteralType: Swift._ExpressibleByBuiltinFloatLiteral", referenced from:
      l_got.$ss25ExpressibleByFloatLiteralP0cD4TypeAB_s01_ab7BuiltincD0Tn in libYogaKit.a(YGLayoutExtensions.o)
  "__swift_FORCE_LOAD_$_swiftUIKit", referenced from:
      __swift_FORCE_LOAD_$_swiftUIKit_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftUIKit_$_YogaKit)
  "__swift_FORCE_LOAD_$_swiftMetal", referenced from:
      __swift_FORCE_LOAD_$_swiftMetal_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftMetal_$_YogaKit)
  "Swift.Float.init(Swift.Double) -> Swift.Float", referenced from:
      static (extension in YogaKit):CoreGraphics.CGFloat.% postfix(CoreGraphics.CGFloat) -> __C.YGValue in libYogaKit.a(YGLayoutExtensions.o)
      (extension in YogaKit):__C.YGValue.init(CoreGraphics.CGFloat) -> __C.YGValue in libYogaKit.a(YGLayoutExtensions.o)
  "__swift_FORCE_LOAD_$_swiftDarwin", referenced from:
      __swift_FORCE_LOAD_$_swiftDarwin_$_rn64ts in dummy.o
      __swift_FORCE_LOAD_$_swiftDarwin_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftDarwin_$_YogaKit, __swift_FORCE_LOAD_$_swiftDarwin_$_rn64ts )
  "__swift_FORCE_LOAD_$_swiftCoreGraphics", referenced from:
      __swift_FORCE_LOAD_$_swiftCoreGraphics_$_rn64ts in dummy.o
      __swift_FORCE_LOAD_$_swiftCoreGraphics_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftCoreGraphics_$_YogaKit, __swift_FORCE_LOAD_$_swiftCoreGraphics_$_rn64ts )
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

image

"react": "17.0.1",
"react-native": "0.64.0"
node v14.16.0
npm 6.14.11
Xcode 12.4
macOS Big Sur - Chip Apple M1

@ahtishamali09
Copy link

Same Error i tried to create new project and facing this issue

Screenshot 2021-03-18 at 3 37 05 PM

@Yonom
Copy link
Contributor

Yonom commented Mar 18, 2021

In my case, the PhaseScriptExecution script was failing for this reason:

nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"

There seems to be a clash in the environment variables used by react native and nvm?

I solved the issue by uninstalling nvm

Also, make sure you don't have any spaces in the project path

@giuseppealbrizio
Copy link

This happened also to me upgrading from 0.63 to 0.64. After trying all solutions with no luck, I found that moving the folder to a directory where the path contain no spaces works and build the app successfully.

https://github.com/facebook/react-native/issues/31206

@hudsonfoo
Copy link

Per this article I used: nvm unalias default and my app is now running. Yay

@XTKKKKK
Copy link

XTKKKKK commented Apr 1, 2021

It happened to me as well. You can check the error shell, try to run it via bash directly to check the shell problem.
In my case, I found my bash_profile is accidentally edited by anaconda, after delete it, the project could run again

@girish54321
Copy link

Hi all any update i want to try react-native 0.64 but it never builds for iOS any help.

@marcoisgood
Copy link

same here. cannot solve the issue and it shows command /bin/sh failed with exit code 11.
any idea?

@ferdicus
Copy link
Contributor

ferdicus commented Apr 7, 2021

In my case, the PhaseScriptExecution script was failing for this reason:

nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"

There seems to be a clash in the environment variables used by react native and nvm?

I solved the issue by uninstalling nvm

Also, make sure you don't have any spaces in the project path

I guess that's a solution 😄

Any workarounds without nuking nvm would be more than welcome though

@IMaz6
Copy link

IMaz6 commented Apr 7, 2021

Same issue here. Upgrading flipper doesn't change anything - also looking for a solution without uninstalling nvm.

@ferdicus
Copy link
Contributor

ferdicus commented Apr 8, 2021

Per this article I used: nvm unalias default and my app is now running. Yay

This only throws an Alias default doesn't exist! error for me 😞

Additionally the linked article explains how to install nvm via homebrew, which is something that nvm maintainers are explicitly recommending against, as it's not supported by them, just FYI

@ferdicus
Copy link
Contributor

ferdicus commented Apr 8, 2021

Interesting tidbit, when building via XCode it does not complain, compiles and installs on the simulator.
I only encounter this issue when trying to build via command line react-native run-ios 🤔

@ferdicus
Copy link
Contributor

ferdicus commented Apr 8, 2021

Ok, this comment on another ticket resolved the issue for me:

I'm using NVM and had the same issue for now I changed the file node_modules/react-native/scripts/find-node.sh adding before set -e:

unset npm_config_prefix
unset PREFIX

@IMaz6
Copy link

IMaz6 commented Apr 9, 2021

Ok, this comment on another ticket resolved the issue for me:

I'm using NVM and had the same issue for now I changed the file node_modules/react-native/scripts/find-node.sh adding before set -e:

unset npm_config_prefix
unset PREFIX

Doesn't work for me. :/
Note I am running this in CircleCi pipeline.

Node: 12.18.4
xcode: 12.4
detox: 18

@rdsedmundo
Copy link

rdsedmundo commented Apr 10, 2021

I have figured out a solution, if you're using nvm make sure you don't have another globally installed version of Node/npm.

If you aren't sure whether or not you have a global version, go to your bash_profile/zshrc and comment the three nvm initialization lines (export NVM_DIR="$HOME/.nvm" [...]), then open a new terminal and do node --version, if it still finds something it means that you have a global version somewhere, and you can find its path with which node.

In my case I'm using Homebrew, and I had a global version of Node that I wasn't even aware coming from the yarn formula, I discovered it after running brew uses --installed node. I went ahead and uninstalled yarn using brew uninstall --force yarn, which automatically uninstalled its node/npm dependency, then uncommented the nvm initialization lines, and then I reinstalled yarn using nvm's npm with npm i -g yarn, and now everything works.

As for a proper resolution on the react-native repo, I suspect that the problem is somehow coming from find-node.sh which is a new file on 0.64. Can't really confirm or propose a solution though. cc @hramos

@serdargun
Copy link

Here what worked for me. I was using node version 15.14.0 because homebrew automatically installed this version. I uninstalled node with brew uninstall node

After that I installed node from official website with exact version 14.16.1. When installation done I clean my project with Cmd + Shift + K and run.

@Liqiankun
Copy link

rm -rf ~/.nvm

This works for me!!!!

@bujoralexandru
Copy link

bujoralexandru commented Apr 20, 2021

I have figured out a solution, if you're using nvm make sure you don't have another globally installed version of Node/npm.

If you aren't sure whether or not you have a global version, go to your bash_profile/zshrc and comment the three nvm initialization lines (export NVM_DIR="$HOME/.nvm" [...]), then open a new terminal and do node --version, if it still finds something it means that you have a global version somewhere, and you can find its path with which node.

In my case I'm using Homebrew, and I had a global version of Node that I wasn't even aware coming from the yarn formula, I discovered it after running brew uses --installed node. I went ahead and uninstalled yarn using brew uninstall --force yarn, which automatically uninstalled its node/npm dependency, then uncommented the nvm initialization lines, and then I reinstalled yarn using nvm's npm with npm i -g yarn, and now everything works.

As for a proper resolution on the react-native repo, I suspect that the problem is somehow coming from find-node.sh which is a new file on 0.64. Can't really confirm or propose a solution though. cc @hramos

After doing what @rdsedmundo suggested, I still didn't came by a fix so then I read the error logs a little closer and it suggested me to do:

To replace NODE_BINARY=node
image
with the actual result of the which node command, which in my case looks something like this:
image

Also CMD-Shift-K to clean the build folder (just to make sure), then build again, and everything worked fine. This method might come in handy for those who still want to keep nvm.

This worked for me, hope it helps whomever stumbles across this problem.

@nubo94
Copy link

nubo94 commented Apr 22, 2021

Per this article I used: nvm unalias default and my app is now running. Yay

Work for me, thanks!

@tvtruong3964
Copy link

I have figured out a solution, if you're using nvm make sure you don't have another globally installed version of Node/npm.

If you aren't sure whether or not you have a global version, go to your bash_profile/zshrc and comment the three nvm initialization lines (export NVM_DIR="$HOME/.nvm" [...]), then open a new terminal and do node --version, if it still finds something it means that you have a global version somewhere, and you can find its path with which node.

In my case I'm using Homebrew, and I had a global version of Node that I wasn't even aware coming from the yarn formula, I discovered it after running brew uses --installed node. I went ahead and uninstalled yarn using brew uninstall --force yarn, which automatically uninstalled its node/npm dependency, then uncommented the nvm initialization lines, and then I reinstalled yarn using nvm's npm with npm i -g yarn, and now everything works.

As for a proper resolution on the react-native repo, I suspect that the problem is somehow coming from find-node.sh which is a new file on 0.64. Can't really confirm or propose a solution though. cc @hramos

it's work for me.

Thank you

@zees98
Copy link

zees98 commented Apr 28, 2021

I have figured out a solution, if you're using nvm make sure you don't have another globally installed version of Node/npm.

If you aren't sure whether or not you have a global version, go to your bash_profile/zshrc and comment the three nvm initialization lines (export NVM_DIR="$HOME/.nvm" [...]), then open a new terminal and do node --version, if it still finds something it means that you have a global version somewhere, and you can find its path with which node.

In my case I'm using Homebrew, and I had a global version of Node that I wasn't even aware coming from the yarn formula, I discovered it after running brew uses --installed node. I went ahead and uninstalled yarn using brew uninstall --force yarn, which automatically uninstalled its node/npm dependency, then uncommented the nvm initialization lines, and then I reinstalled yarn using nvm's npm with npm i -g yarn, and now everything works.

As for a proper resolution on the react-native repo, I suspect that the problem is somehow coming from find-node.sh which is a new file on 0.64. Can't really confirm or propose a solution though. cc @hramos

OMG! Thank you so much. I've been pulling my hair out over this for 2 days. You rock!

@rlsbelmiro
Copy link

rlsbelmiro commented Apr 30, 2021

I have figured out a solution, if you're using nvm make sure you don't have another globally installed version of Node/npm.
If you aren't sure whether or not you have a global version, go to your bash_profile/zshrc and comment the three nvm initialization lines (export NVM_DIR="$HOME/.nvm" [...]), then open a new terminal and do node --version, if it still finds something it means that you have a global version somewhere, and you can find its path with which node.
In my case I'm using Homebrew, and I had a global version of Node that I wasn't even aware coming from the yarn formula, I discovered it after running brew uses --installed node. I went ahead and uninstalled yarn using brew uninstall --force yarn, which automatically uninstalled its node/npm dependency, then uncommented the nvm initialization lines, and then I reinstalled yarn using nvm's npm with npm i -g yarn, and now everything works.
As for a proper resolution on the react-native repo, I suspect that the problem is somehow coming from find-node.sh which is a new file on 0.64. Can't really confirm or propose a solution though. cc @hramos

After doing what @rdsedmundo suggested, I still didn't came by a fix so then I read the error logs a little closer and it suggested me to do:

To replace NODE_BINARY=node
image
with the actual result of the which node command, which in my case looks something like this:
image

Also CMD-Shift-K to clean the build folder (just to make sure), then build again, and everything worked fine. This method might come in handy for those who still want to keep nvm.

This worked for me, hope it helps whomever stumbles across this problem.

Thank you @bujoralexandru It's worked for me.

@mjstelly
Copy link

Per this article I used: nvm unalias default and my app is now running. Yay

Where should I run this command?

Run it from CLI

@mjstelly
Copy link

Per this article I used: nvm unalias default and my app is now running. Yay

I'm totally dumbfounded! Something so friggin simple and obscure brought my work to a screeching halt for a day and a half! If I had any hair, I'd be pulling it out! For those as frustrated as I was, try this first. ☝🏻

@DibyajyotiMishra
Copy link

DibyajyotiMishra commented Oct 21, 2021

Hey guys, I found the root cause is in

source "$RN_DIR/scripts/find-node.sh"

where $RN_DIR is undefined.
Replace source "$RN_DIR/scripts/find-node.sh" with source "$REACT_NATIVE_DIR/scripts/find-node.sh" solves the issue.

Relates to 322e8f7

This is resolved in the latest version of react-native (0.66.1)

@jadonhansen
Copy link

jadonhansen commented Nov 5, 2021

I had the same issue and solved it by navigating to: your app target -> Build Phases -> Bundle React Native code and images:
Screenshot 2021-11-05 at 15 23 25

The fix for me was changing the "export NODE_BINARY" value to the above value which I got from running which node in the terminal.
Basically, what you want there is the path to your node binary. Whether you're using nvm or not, it shouldn't matter.

@lukeacl
Copy link

lukeacl commented Nov 9, 2021

For those having this issue, I'm using NVM, I found the path of node I had active in NVM and symlinked it to /usr/local/bin/node. The other solutions above didn't work where you export NODE_BINARY etc. This fix is more of a workaround and will need to be adjusted over time / removed. Not ideal, but it works.

% which node

/Users/luke/.nvm/versions/node/v14.17.5/bin/node

sudo ln -s /Users/luke/.nvm/versions/node/v14.17.5/bin/node /usr/local/bin/node

danilobuerger pushed a commit to feastr/react-native that referenced this issue Nov 13, 2021
Summary:
Some users have `node` installed globally which sets a `PREFIX` by default (so it knows where to put pkgs). We are looking for the "right" node on the next step anyway and if the user is using `nvm`, `PREFIX` breaks it.

closes facebook#31181

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Fixed] - Ignores global npm prefix

Pull Request resolved: facebook#31740

Test Plan:
`yarn ios` now works, even if there's a `usr/local/bin/npm`

<img width="493" alt="Screen Shot 2021-06-17 at 10 14 08 AM" src="https://user-images.githubusercontent.com/2659478/122413946-c2f57200-cf54-11eb-817c-bd3c07ac50bf.png">

Reviewed By: yungsters

Differential Revision: D31237363

Pulled By: charlesbdudley

fbshipit-source-id: 4ee9c04f8b8ab4e815bafbe2d02e589d621577b4
danilobuerger pushed a commit to feastr/react-native that referenced this issue Nov 19, 2021
Summary:
Some users have `node` installed globally which sets a `PREFIX` by default (so it knows where to put pkgs). We are looking for the "right" node on the next step anyway and if the user is using `nvm`, `PREFIX` breaks it.

closes facebook#31181

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Fixed] - Ignores global npm prefix

Pull Request resolved: facebook#31740

Test Plan:
`yarn ios` now works, even if there's a `usr/local/bin/npm`

<img width="493" alt="Screen Shot 2021-06-17 at 10 14 08 AM" src="https://user-images.githubusercontent.com/2659478/122413946-c2f57200-cf54-11eb-817c-bd3c07ac50bf.png">

Reviewed By: yungsters

Differential Revision: D31237363

Pulled By: charlesbdudley

fbshipit-source-id: 4ee9c04f8b8ab4e815bafbe2d02e589d621577b4
@smanzini
Copy link

smanzini commented Dec 9, 2021

In my case, the PhaseScriptExecution script was failing for this reason:

nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"

There seems to be a clash in the environment variables used by react native and nvm?

I solved the issue by uninstalling nvm

Also, make sure you don't have any spaces in the project path

Hi @Yonom,
how did you discover that in your the reason was 'nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local" '
I've uninstalled nvm as well, but still error happens while it's running custom shell script 'Bundle React Native code and images' -> ERROR: Command PhaseScriptExecution failed with a nonzero exit code

Could you please help me?
Many thanks
Stefano

@princefishthrower
Copy link

Fantastic and insightful comments here, which led to my solution.

I'll add my specific solution to the pot: in my case, I also had nodenv installed, not sure how or why, I don't remember, I've always been an nvm user. (Great that we have two tools for the exact same task out there 🙄) anyway, I nuked it:

brew uninstall nodenv

But then I still had to do:

rm -R /Users/myuser/.nodenv/

And even then I still had to manually remove this line in my .zshrc (NOT .zprofile):

eval "$(nodenv init -)"

Whew, builds working again in XCode 😅

@magiskaoskar
Copy link

Updating nvm fixed it for me.
https://github.com/nvm-sh/nvm#installing-and-updating

@syedamirali14
Copy link

removing set -e from Bundle React Native code images works for me in M1 Monterey, Xcode 13.1

danilobuerger pushed a commit to feastr/react-native that referenced this issue Jan 31, 2022
Summary:
Some users have `node` installed globally which sets a `PREFIX` by default (so it knows where to put pkgs). We are looking for the "right" node on the next step anyway and if the user is using `nvm`, `PREFIX` breaks it.

closes facebook#31181

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Fixed] - Ignores global npm prefix

Pull Request resolved: facebook#31740

Test Plan:
`yarn ios` now works, even if there's a `usr/local/bin/npm`

<img width="493" alt="Screen Shot 2021-06-17 at 10 14 08 AM" src="https://user-images.githubusercontent.com/2659478/122413946-c2f57200-cf54-11eb-817c-bd3c07ac50bf.png">

Reviewed By: yungsters

Differential Revision: D31237363

Pulled By: charlesbdudley

fbshipit-source-id: 4ee9c04f8b8ab4e815bafbe2d02e589d621577b4
@syedamirali14
Copy link

syedamirali14 commented Feb 4, 2022

i fixed it
go to your terminal write nano .profile remove everything and save it
run the build and it will work.
this was happening because of environment variables conflict of NVM set in .profile

@lclarkg18
Copy link

lclarkg18 commented Feb 6, 2022

I did several things so it's hard to know which one did it:

  • Make sure you don't have errors in your bash or zshrc profile -> I had a error related to my jdk. You will know this if it when opening a terminal window it shows an error/warning
  • Make sure you don't have spaces in the path
  • If you are using Firebase, make sure your GoogleService-Info file is in the ios folder and not in the ios>project folder
  • Do not keep the project in an iCloud folder, especially if you are low on space. I suspect this was a big factor for mine.

Finally, my worked when doing these and running react-native 0.67.2. The newer version on it's own didn't fix it, I had to do at least one of these other assertions to get it working

Things to consider:

  • Running the project in Xcode will usually give you more insight into the problem
  • Clearing the Xcode build folder wasn't enough on it's own to fix it but when trying a potential solution it is important you do it (and potentially also pod deintegrate && pod install) to make sure there are no traces of the previous ios build.
  • I am running node version 16.13, running node 17 gave me different errors and I wouldn't recommend it to date.

I am running macOS Monterrey and Xcode 13.2.1, but I tried on BigSur and also Xcode 12.5.1 and the still got the error.

@zabojad
Copy link

zabojad commented Feb 16, 2022

In my case, re-installing nvm solved it.

@TheWirv
Copy link
Contributor

TheWirv commented Feb 24, 2022

For those having this issue, I'm using NVM, I found the path of node I had active in NVM and symlinked it to /usr/local/bin/node. The other solutions above didn't work where you export NODE_BINARY etc. This fix is more of a workaround and will need to be adjusted over time / removed. Not ideal, but it works.

% which node

/Users/luke/.nvm/versions/node/v14.17.5/bin/node

sudo ln -s /Users/luke/.nvm/versions/node/v14.17.5/bin/node /usr/local/bin/node

Thank you so much, this solved my problem! I have node (v16.14.0) installed via brew and don't use nvm at all. I encountered this problem after upgrading from React Native v0.66.4 to v0.67.3.

@Unimakura
Copy link

Thank you so much, this solved my problem! I have node (v16.14.0) installed via brew and don't use nvm at all.

Thanks!
I solved my problem the same way.

$ which node
/Users/xxxx/.nodebrew/current/bin/node
$ ln -s /Users/xxxx/.nodebrew/current/bin/node /usr/local/bin/node

@dppo
Copy link

dppo commented Mar 7, 2022

For those having this issue, I'm using NVM, I found the path of node I had active in NVM and symlinked it to /usr/local/bin/node. The other solutions above didn't work where you export NODE_BINARY etc. This fix is more of a workaround and will need to be adjusted over time / removed. Not ideal, but it works.

% which node

/Users/luke/.nvm/versions/node/v14.17.5/bin/node

sudo ln -s /Users/luke/.nvm/versions/node/v14.17.5/bin/node /usr/local/bin/node

Thanks!
I solved my problem the same way.

@JDMathew
Copy link
Contributor

JDMathew commented Mar 8, 2022

Instead of removing nvm or removing nvm's default alias one could simple patch react-native's node_modules.

Update node_modules/react-native/scripts/find-node.sh around line 22 - 28

if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
  # shellcheck source=/dev/null
-  . "$HOME/.nvm/nvm.sh"
+  . "$HOME/.nvm/nvm.sh" --no-use
+  nvm use 2> /dev/null || nvm use default
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
  # shellcheck source=/dev/null
-  . "$(brew --prefix nvm)/nvm.sh"
+  . "$(brew --prefix nvm)/nvm.sh" --no-use
+  nvm use 2> /dev/null || nvm use default
fi

@alancwoo
Copy link

alancwoo commented Mar 9, 2022

In a completely freshly initialized project generated via npx react-native init AwesomeProject with react-native 0.67.3, I'm still unable to build. I've tried manually setting the path to my nvm node via the xcode interface as well as symlinking it overtop /usr/local/bin/node to no avail.

My node_modules/react-native/scripts/find-node.sh already looks like the recommended version above in #31181 (comment)

Building via npx react-native run-ios also fails:

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

Monterey 12.2.1 (21D62)
Xcode Version 13.2.1 (13C100)
Node v16.14.0 (installed via nvm)
React Native 0.67.3

@JDMathew
Copy link
Contributor

JDMathew commented Mar 9, 2022

@alancwoo did you install cocoapods via gem (i.e. sudo gem install cocoapods)? If so try installing via brew.

First remove cocoapods with sudo gem uninstall cocoapods and then run brew install cocoapods.

If you're still having issues try sudo gem install ffi it may help with pod optimisations.

I had issues with installing pods when using cocoapods installed via gem. I think it's a rossetta issue.

I am running the exact same setup:
Monterey 12.2.1 (21D62)
Xcode Version 13.2.1 (13C100)
Node v16.14.0 (installed via nvm)
React Native 0.67.3

@mdlavin
Copy link

mdlavin commented Apr 15, 2022

I ran into this failure too. I also debugged it down to the . "$HOME/.nvm/nvm.sh" line. However, I came up with a different solution. For me, mine was failing because nvm's default was pointing to an uninstalled version. If I set nvm's default to an installed version, like nvm alias default v14 then it started to work

@ZohaibAhmad786
Copy link

Per this article I used: nvm unalias default and my app is now running. Yay

You saved my day

@idesignpixels
Copy link

Took me awhile but I ran the following and it now works 🥳
nvm unalias default
Then
nvm alias default 14.17.3

You could conceivably just run the last one...

@sadohert
Copy link

I just had a similar issue. I had previously had this issue and nvm unalias default got me around it.

This time that approach did not fix it. I started to re-create the steps that were happening on that PhaseScriptExecution and I believe the find_node.sh script it uses was exited the shell (I could see my iTerm2 tab disappear every time I tried to run it).

I ended up upgrading nvm using the Upgrade Instructions and I was finally able to successfully build.

@itsjhonny
Copy link

itsjhonny commented Jul 7, 2022

For those having this issue, I'm using NVM, I found the path of node I had active in NVM and symlinked it to /usr/local/bin/node. The other solutions above didn't work where you export NODE_BINARY etc. This fix is more of a workaround and will need to be adjusted over time / removed. Not ideal, but it works.

% which node

/Users/luke/.nvm/versions/node/v14.17.5/bin/node

sudo ln -s /Users/luke/.nvm/versions/node/v14.17.5/bin/node /usr/local/bin/node

This solved for me using nvm and node 16.16.0
xcode 13.4.1
react-native 0.68.2

@Brad19
Copy link

Brad19 commented Sep 29, 2022

I have figured out a solution, if you're using nvm make sure you don't have another globally installed version of Node/npm.

If you aren't sure whether or not you have a global version, go to your bash_profile/zshrc and comment the three nvm initialization lines (export NVM_DIR="$HOME/.nvm" [...]), then open a new terminal and do node --version, if it still finds something it means that you have a global version somewhere, and you can find its path with which node.

In my case I'm using Homebrew, and I had a global version of Node that I wasn't even aware coming from the yarn formula, I discovered it after running brew uses --installed node. I went ahead and uninstalled yarn using brew uninstall --force yarn, which automatically uninstalled its node/npm dependency, then uncommented the nvm initialization lines, and then I reinstalled yarn using nvm's npm with npm i -g yarn, and now everything works.

As for a proper resolution on the react-native repo, I suspect that the problem is somehow coming from find-node.sh which is a new file on 0.64. Can't really confirm or propose a solution though. cc @hramos

This truely worked for me..

Since I'm using M2 macbook pro and building the ios and android via fastlane, i encountered this issue and unsure what to do. I was looking out every where for the solution, finally I found this, based on that i realised that i've installed yarn via brew and not via npm. so uninstalling the yarn and re-installing via npm -g made a big difference. It made my day. Thanks for this
post.

Cheers,
Brad

@facebook facebook locked as resolved and limited conversation to collaborators Sep 30, 2022
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Sep 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Triage 🔍 Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

Successfully merging a pull request may close this issue.