56

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?

Ronan Boiteau
  • 8,910
  • 6
  • 33
  • 52
Seeliang
  • 1,713
  • 1
  • 11
  • 18
  • 1
    your node version ? – Arunkumar Jun 12 '17 at 05:53
  • 3
    Are you using nvm? – Steve Potter Jun 12 '18 at 21:33
  • This happened to me as well with an Expo Bare Workflow project: Node is installed via `nodenv` and Expo is installed via `expo init ExpoBareTest`. During the build, the `node` binary cannot be found, even though Xcode builds are working with regular (non-Expo) React Native projects.- Both solutions given below, the `export NODE_BINARY=/path/to/node` as well as `ln -s $(which node) /usr/local/bin/node`, work correctly in this case. (Just adding this as neither Expo nor nodenv was mentioned in this context before.) – ChrisW May 25 '21 at 08:48

11 Answers11

209

@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

josesuero
  • 2,438
  • 2
  • 12
  • 19
  • 3
    I think this is a much cleaner solution. The modification to build phase solution would cause a modification to the project which may impact other team members working on the same project with different env setup. – jyliang Mar 11 '19 at 17:03
  • 5
    for `nvm` users, this is the solution to building your `react-native` app on Xcode when facing `env: node: No such file or directory`. – kenmistry May 28 '19 at 05:14
  • Thank you so much. I just set up a new Mac and couldn't figure out why I was getting this error when building my app, despite my setup being the same as my old Mac (Node.js installed via n, for example). Regardless, this fixed it so thanks again. – Darryl Young Nov 13 '20 at 10:45
  • Amazing! Thanks for your effort! – Ahmed Mahmoud Feb 17 '21 at 09:12
  • Thank you so much @josesureo your suggestion worked like a charm. – Mohit Kale Jul 09 '21 at 11:45
  • 4
    On new M1 Mac I had to `cd /usr/local` then `mkdir bin` (or just `sudo mkdir /usr/local/bin`) first. – Leo Jul 11 '21 at 10:35
  • 1
    This messed up anything to do with node on my machine for me... I couldn't run other node commands like `gatsby develop` or `ntl dev` for example... I fixed the issue by reverting and deleting `node` in `/usr/local/bin` – fullStackChris Oct 15 '21 at 13:13
  • Brilliant ! Thank you for @josesuero !! – rudenick Jan 17 '22 at 03:51
  • You might want to create a symlink to actual node dir if you're using nodeenv: `ln -s $(nodenv which node) /usr/local/bin/node` – Arthur Wang Jan 17 '22 at 09:28
62

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

Philipp Kyeck
  • 17,628
  • 15
  • 79
  • 117
Seeliang
  • 1,713
  • 1
  • 11
  • 18
  • 47
    It could be better creating a symlink as following: `ln -s $(which node) /usr/local/bin/node` and leave the ios app configuration as default. :) – brunocascio Oct 10 '17 at 23:00
  • 1
    great! you saved me :D – bkit4u Feb 08 '18 at 10:02
  • 3
    Hi, path has changed from `node_modules/react-native/packager/react-native-xcode.sh` to `node_modules/react-native/scripts/react-native-xcode.sh` – dreadcast May 04 '18 at 08:34
  • For me below worked as mentioned by dreadcase. export NODE_BINARY=/usr/local/bin/node node_modules/react-native/scripts/react-native-xcode.sh to node_modules/react-native/scripts/react-native-xcode.sh – Muhammad Maqsood Apr 30 '21 at 17:29
  • 1
    Do not do this, this is a hack and will make your build brittle. This is committing a hard-coded environment configuration to your repo. – Philihp Busby Mar 30 '22 at 18:08
16

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.

Maxime B
  • 181
  • 1
  • 7
4

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.

johndpope
  • 4,597
  • 2
  • 38
  • 39
Alex
  • 784
  • 4
  • 10
3

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.

TechnoTim
  • 2,697
  • 1
  • 21
  • 27
3
nvm alias default 14

OR

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

This made my Xcode 12.4 see node

Rashid Latif
  • 2,121
  • 19
  • 23
F Mamali
  • 31
  • 2
1

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
Jatin Mehrotra
  • 5,637
  • 1
  • 12
  • 41
Roberto
  • 11
  • 1
1

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.

Preetika
  • 456
  • 4
  • 15
-1

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

user3009752
  • 154
  • 2
  • 9
  • 24
-1

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.

  • Not sure why you're so down-voted. Another answer on a different question is the same, with a score of 200. Oh well – SeanMC May 02 '22 at 16:04
-6

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

Arunkumar
  • 1,635
  • 1
  • 15
  • 25