'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



Solution 1:[1]

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

It resolved.

Solution 2:[2]

@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.

Solution 3:[3]

On my Mac M1 the folder /usr/local/bin was missing so I had the error :

ln: /usr/local/bin/node: No such file or directory

So here is what I did :

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pekanchuan
Solution 2 Kumar Gaurav
Solution 3 ZazOufUmI