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."
Asked Answered
J

3

22
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

Jollanta answered 30/4, 2021 at 17:5 Comment(0)
J
66
sudo ln -s $(which node) /usr/local/bin/node

It resolved.

Jollanta answered 1/5, 2021 at 3:42 Comment(8)
Thanks mate at least helped me to solve one build issue of M1s..Decontaminate
what if i already have that and it still doesn't work?Sejant
Not working on my M1Lampe
Not on mine either. Do you need to reboot or something to allow this to take affect properly? Maybe a background java or gradle daemon running? I'll give that a try.Squelch
Nope. Restart didn't do it either. Ugh, I guess starting Android Studio through the terminal is how it's gotta be for now...Squelch
this worked for my m1 , xcode 13Calculate
This works great, unless you have multiple users on the same device, or need to change node versions (in which case you need to delete the symlink and create it again)Popeyed
@JoshuaPinter Still doesn't work for me. No matter I start Android Studio from terminal or not. My node is installed through nvm.Tawnatawney
K
14

@pekanchuan 's answer at https://mcmap.net/q/567907/-new-rn-project-in-m1-mbp-built-failed-quot-could-not-find-node-make-sure-it-is-in-bash-path-or-set-the-node_binary-environment-variable-quot 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.

Konstanz answered 27/7, 2021 at 12:59 Comment(0)
W
5

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
White answered 30/3, 2022 at 19:44 Comment(1)
than you so much, this unblocked meLipoprotein

© 2022 - 2024 — McMap. All rights reserved.