React Native ios build : Can't find node

Iosnode.jsReact NativeBuild

Ios Problem Overview


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?

Ios Solutions


Solution 1 - Ios

@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

Solution 2 - Ios

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 3 - Ios

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.

Solution 4 - Ios

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.

Solution 5 - Ios

nvm alias default 14

OR

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

This made my Xcode 12.4 see node

Solution 6 - Ios

For anyone that stumbles upon this in 2022 here is my situation and how I fixed it.

  1. react-native --version -> 4.14
  2. npx --version -> 6.14.9
  3. node --version -> 12.14.1
  4. We use TypeScript also.

XCode "Bundle React Native code and images"

enter image description here

export ENTRY_FILE=src/App.tsx
../node_modules/react-native/scripts/react-native-xcode.sh
../node_modules/expo-constants/scripts/get-app-config-ios.sh
../node_modules/expo-updates/scripts/create-manifest-ios.sh

Remove the export NODE_BINARY=node line of code. It's not needed anymore. The way I figured this out was reading through the source code found in ../node_modules/react-native/scripts/react-native-xcode.sh If you look there, you'll find nvm/node sourcing being done for you.

Solution 7 - Ios

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

Solution 8 - Ios

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 9 - Ios

If you are using Mac, check if you have installed node with brew. In this case it cannot find the path. Install node by downloading from the official website

Solution 10 - Ios

The best solution is to actually do ln -s $(which node) /usr/local/bin, this will create a "symlink" from /usr/local/bin/node to wherever your node is, this is important because most apps looks at node at this path. You probably don't want to do export NODE_BINARY=[your node path] because when another teammate has a different OS or different installation of node (i.e., one is using nvm the other is using homebrew), then the same error will occur, it will also happen when building for production. So just go with ln -s $(which node) /usr/local/bin to be safe.

Solution 11 - Ios

Open Xcode, then choose "Preferences..." from the Xcode menu.

Go to the Locations panel and install the tools by selecting the most recent version in the Command Line Tools dropdown.

select command line tools like as this image enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSeeliangView Question on Stackoverflow
Solution 1 - IosjosesueroView Answer on Stackoverflow
Solution 2 - IosSeeliangView Answer on Stackoverflow
Solution 3 - IosMaxime BView Answer on Stackoverflow
Solution 4 - IosTechnoTimView Answer on Stackoverflow
Solution 5 - IosF MamaliView Answer on Stackoverflow
Solution 6 - IosAlexView Answer on Stackoverflow
Solution 7 - IosRobertoView Answer on Stackoverflow
Solution 8 - IosPreetikaView Answer on Stackoverflow
Solution 9 - Iosuser3009752View Answer on Stackoverflow
Solution 10 - IosaprilmintacpinedaView Answer on Stackoverflow
Solution 11 - IosArunkumarView Answer on Stackoverflow