React Native ios build : Can't find node

I have a prototype ready to go and the project is jammed with build:

error: Can't find 'node' binary to build React Native bundle If you have non-standard nodejs installation, select your project in Xcode, find 'Build Phases' - 'Bundle React Native code and images' and change NODE_BINARY to absolute path to your node executable (you can find it by invoking 'which node' in the terminal)

this feedback is helpless for me, i do have node with nvm. is this something related to bash?


@brunocascio solution on the comment is simpler and less invasive, create a symlink to node, on command line:

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

Update:

On new M1 Mac I had to cd /usr/local then mkdir bin (or just sudo mkdir /usr/local/bin) first.

thanks leo for the comment


I found one solution

First find your current node, in shell

which node

then copy your node url to

export NODE_BINARY=[your node path]
../node_modules/react-native/packager/react-native-xcode.sh to node_modules/react-native/scripts/react-native-xcode.sh

enter image description here


Solution for nvm users :

In your build phases scripts, just add

# Fix for machines using nvm
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
. "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
. "$(brew --prefix nvm)/nvm.sh"
fi

Above export NODE_BINARY=node. This will make Xcode work regardless of your machine using nvm.


The solution for me is to set a default version of node with nvm in your profile. This works for bash or zsh:

Add this to your .zshrc or .bashrc

# default node version for nvm
nvm use 8.9.3

Be sure to change it to the version you want when starting a new terminal.


If you are developing a React Native based solution and you are using NVM for local Node versioning, the error may be due to this.

XCode cannot find the Node version, of course XCode fetches the Node in the / usr / local / bin / node directory and NVM stores the Node in another directory like Users / $ {my-user} /. Nvm / versions /node/v14.16.0/bin/node

To work it is enough to create an alias for XCode to find the Node in its default search:

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