Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New RN project in M1 mbp built failed. "Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable."

System:
    OS: macOS 11.3
    CPU: (8) arm64 Apple M1
    Memory: 124.86 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.0.0 - /opt/homebrew/bin/node
    Yarn: Not Found
    npm: 7.10.0 - /opt/homebrew/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.10.1 - /Users/chia/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK: Not Found
  IDEs:
    Android Studio: Not Found
    Xcode: 12.5/12E262 - /usr/bin/xcodebuild
  Languages:
    Java: Not Found
  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

New RN project create successful, but built failed by Xcode.

Error:

Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable.

Command PhaseScriptExecution failed with a nonzero exit code

node installed by homebrew, and Intel mbp doesn't have this error.

How to resolve this error?

Node in the PATH

npm -g bin /opt/homebrew/bin

echo $PATH /Users/chia/.pyenv/shims:/Users/chia/.rbenv/shims:/Users/chia/.rbenv/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

like image 271
pekanchuan Avatar asked Apr 30 '21 17:04

pekanchuan


2 Answers

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

It resolved.

like image 110
pekanchuan Avatar answered Nov 16 '22 20:11

pekanchuan


@pekanchuan 's answer at https://stackoverflow.com/a/67342683/6512858 worked for me.

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

I would like to add though that if this command says /usr/local/bin/node: File exists you need to know that the link already exists to maybe a different version of node. In my case, to install yarn, brew installed a separate nodejs v15 and linked the file to its binary. Although I use nvm to have nodejs v14 and nodejs v16. This extra nodejs was the reason for the error mentioned in question.

Simply run sudo rm -f /usr/local/bin/node to remove the link followed by the command sudo ln -s $(which node) /usr/local/bin/node to create correct link.

like image 12
Kumar Gaurav Avatar answered Nov 16 '22 20:11

Kumar Gaurav