130

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?

3
  • 1
    your node version ? Commented Jun 12, 2017 at 5:53
  • 3
    Are you using nvm? Commented Jun 12, 2018 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.) Commented May 25, 2021 at 8:48

24 Answers 24

342

@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

Sign up to request clarification or add additional context in comments.

13 Comments

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.
for nvm users, this is the solution to building your react-native app on Xcode when facing env: node: No such file or directory.
On new M1 Mac I had to cd /usr/local then mkdir bin (or just sudo mkdir /usr/local/bin) first.
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
put sudo in front of answer if you get Permission Denied —> sudo ln -s $(which node) /usr/local/bin/node
|
107

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

6 Comments

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. :)
great! you saved me :D
Hi, path has changed from node_modules/react-native/packager/react-native-xcode.sh to node_modules/react-native/scripts/react-native-xcode.sh
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
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.
|
51

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.

3 Comments

This! This is the correct answer. This has helped me get my React Native projects up an running using the Node installed via NVM.
Didn't work for me
This is a better answer indeed. But more code can lead to more breakage so I don't know how to feel about it.
28

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:

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

2 Comments

Although this solution is mentioned in various answers, ++ to @Roberto for providing an explanation.
nihalsaeed@Nihals-Mac-mini ios % sudo ln -s $(which node) /usr/local/bin/node Password: ln: /usr/local/bin/node: File exists
19

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"

Xcode settings, build phases, bundle react native code and images location

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.

3 Comments

Thanks for pointing out the script where they set the NODE_BINARY env! Super helpful!
Thanks for this, it lead me in the right direction. After upgrading to node 21.2.0 via NVM with an older React (0.67.5) I kept running into build issues, either on the simulator or device. What worked for me was removing all of the shell code and leaving it blank.
EDIT: ignore my above comment, this was not the way. This did the trick and I ended up patching my react-native package: stackoverflow.com/a/77153566/500182
18

In 2022 the default build looks in ios/.xcode.env.local and ios/.xcode.env for environment customizations. The provided .xcode.env has an example enabling nvm and setting NODE_BINARY.

This is configured in Build Phases -> Bundle React Native code and images. The shell script looks as follows circa 10/2022:

set -e

WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"

/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"

The Input Files section for this script has

$(SRCROOT)/.xcode.env.local
$(SRCROOT)/.xcode.env

The default .xcode.env looks like this now:

# This `.xcode.env` file is versioned and is used to source the environment
# used when running script phases inside Xcode.
# To customize your local environment, you can create an `.xcode.env.local`
# file that is not versioned.

# NODE_BINARY variable contains the PATH to the node executable.
#
# Customize the NODE_BINARY variable here.
# For example, to use nvm with brew, add the following line
#. "$(brew --prefix nvm)/nvm.sh" --no-use
export NODE_BINARY=$(command -v node)

To reliably get node set, configure your project properties to the current default values and update one of the two reference env files.

My ios/.xcode.env looks like this:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
export NODE_BINARY=$(command -v node)

3 Comments

it compiles and spits out the build - but is it the wrong node version? I'm using nvm 16 - but system wants 17. how to target nvm 16?
See above where I added my example .xcode.env file. You need to load nvm so it'll pick up your selected nvm default.
In my case some magic happened that got the wrong node link to homebrew in .xcode.env.local , I has to change the contents to : export NODE_BINARY=/opt/homebrew/Cellar/node/23.6.0/bin/node and it worked.
14
nvm alias default 14

OR

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

This made my Xcode 12.4 see node

Comments

6

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.

3 Comments

Not sure why you're so down-voted. Another answer on a different question is the same, with a score of 200. Oh well
When i run this command, It says "File exist". But i am still getting the same error
This should be the correct method as you don't need to change the NODE_BINARY for every script that needs it.
6

For users who migrate to react-native 0.70.* and get a similar error, I fixed it by adding in Build Phases section:

set -e

WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"

/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"

enter image description here

And in the iOS directory create the file .xcode.env.local (doc)

# This `.xcode.env` file is versioned and is used to source the environment
# used when running script phases inside Xcode.
# To customize your local environment, you can create an `.xcode.env.local`
# file that is not versioned.
# NODE_BINARY variable contains the PATH to the node executable.
#
# Customize the NODE_BINARY variable here.
# For example, to use nvm with brew, add the following line
# . "$(brew --prefix nvm)/nvm.sh" --no-use
export NODE_BINARY=$(which node)

1 Comment

This worked for me, using react-native 0.72.0
5

From the React Native environment setup documentation:

Starting from React Native version 0.69, it is possible to configure the Xcode environment using the .xcode.env file provided by the template.

The .xcode.env file contains an environment variable to export the path to the node executable in the NODE_BINARY variable. This is the suggested approach to decouple the build infrastructure from the system version of node. You should customize this variable with your own path or your own node version manager, if it differs from the default.

so in your project's root directory, look in the ios/ subdirectory, create or update the file .xcode.env to export your node binary:

file: /ios/.xcode.env

# To use nvm with brew, uncomment the line below
# . "$(brew --prefix nvm)/nvm.sh" --no-use
export NODE_BINARY=$(command -v node)

This file will be loaded by Xcode and properly provide the node binary for your build process. Note that if you're using NVM for your node environment, you'll need to uncomment the line to initialize your NVM environment before exporting the node binary.

Hope this helps! :)

Comments

4

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.

1 Comment

after sudo rm -f /usr/local/bin/node NODE was deleted and I should reinstall it
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.

2 Comments

what about nvm use default?
If your default matches the version in your .nvmrc that would work. I like to use the version I specify in my project, which doesn't always match my default.
3

In my case, I had to choose a lower version of node
from node/18.7.0 to node/16.9.0


react-native: 0.66.3
Xcode: 14.1
MacOs: 12.6.1

Comments

2

This error occurs if the path of the "node" changes somehow. I have solved this issue by using this command:

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

Comments

1

Simple latest working solution:

Just replace this line in shell:

export NODE_BINARY=node ../node_modules/react-native/scripts/react-native-xcode.sh

ScreenShot

Comments

1

If you use the NVM tool to manage different versions of the Node then creating a symbolic link to the current default Node version ln -s $(which node) /usr/local/bin/node could break the other projects those expect another version. That happens as in the PATH environment variable the path /usr/local/bin goes before the path of the Node selected by NVM.

React Native and Expo uses the bash shell for build scripts and therefore we just need to set up the bash shell properly to work with NVM. To do that copy the configuration code from the ~/.zshenv into ~/.bash_profile without taking the autocompletion part:

# This file is for the React Native development as it requires the bash shell in the build scripts

# Configure NVM
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh"

Comments

1

If you are using NVM, then the usual cause of this error is NVM not properly initialized in the Bundle React Native Code And Images Build Phase.

To initialize NVM just change the Build Phase script like so:

source $HOME/.zshrc
# If you initialize NVM using .profile uncomment this line:
# source $HOME/.profile
export NODE_BINARY=$(which node)
../node_modules/react-native/scripts/react-native-xcode.sh

Comments

1

In my case I am not fixing the React Native project but I use a React Native integration in my native project. Some dependencies were not seeing the node I had installed using homebrew, although I had it on PATH.

For anyone that stumbles upon the same situation just make sure the /usr/local/bin directory exists and run

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

as mentioned by @F Mamali and @josesuero

Comments

1

If you run into this issue when building your iOS project using react-native 0.73 then this issue may be caused by the presence of an ios/.xcode.env.local file which is setting the NODE_BINARY environment variable during the iOS build to a temporary node location. This can happen if you are using using Yarn.

See also this related RN project issue https://github.com/facebook/react-native/issues/43285

Comments

1

enter image description here

** Note : -> if your node is with NVM, you might need to explicitly set the Node path when using nvm. Try adding this to the top of your Bundle React Native Code and Images script:**

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
export NODE_BINARY="$(which node)"

Comments

0

I will give you the quickest solution not the best.

Open terminal and write which node or command -v node to find out where is your node. It will give you path for me its: /opt/homebrew/bin/node.

Then go to script_phases.sh file under your PROJECT_ROOT/node_modules/react-native/scripts/react-native-pods-utils/script_phases.sh and paste this top of the file.

NODE_BINARY="/opt/homebrew/bin/node"

You might do the same thing for react-native-xcode.sh under the PROJECT_ROOT/node_modules/react-native/scripts/.

Comments

0

This can happen if your project uses a specific node version (via .node-version) that is not installed on your machine.
In my case, .node-version specifies 20.10.0 but I only had 22.18.0 installed.
After installing the correct version (nvm install 20.10.0) XCode was able to build my app properly.
In this case, be careful about adding a symlink like the top answer suggests, because it will resolve node to the current version being used when the symlink is created, which will probably break the use of .node-version.

Comments

-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

Comments

-7

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

1 Comment

Unfair negative answer. This can be helpful. I will recommend checking this with everyone who reads this. If you have the preselected value, choose again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.