Reputation: 2837
I'm getting the following build error when compiling my react-native project in Xcode env: node: No such file or directory
Not sure whats causing it? Node v8.9.4 React-Native v0.50.4 NPM v5.6.0 And I'm using nvm
Upvotes: 26
Views: 20711
Reputation: 5743
I read through all the other answers.
In my case everything was pointing to the right place.
This is .xcode.env.local :
export NODE_BINARY=/opt/local/bin/node
env node
and command -v node
were resolving properly in the terminal to /opt/local/bin/node
which is valid yet the build still failed with env: node: No such file or directory
So I figured that env
when called by xcode was not able to find node because the directory containing it was not it its $PATH
.
So I added the following line at the end of .xcode.env.local
and it worked:
export PATH=$PATH:`dirname $NODE_BINARY`
Upvotes: 0
Reputation: 1404
Check for the presence of a file name ios/.xcode.env.local
which might be taking precedence over your ios/.xcode.env
file that typically sets the NODE_BINARY
environment variable for building React Native projects:
export NODE_BINARY=$(command -v node)
In my case there was a ios/.xcode.env.local
which was setting the NODE_BINARY
using a temporary path under /var/folders/dy/
- this could be seen from the Xcode build output.
I was using Xcode 15.0.1 to build a React Native 0.72.9 project. The React-rncore
CocoaPods pod target was failing due to this (now invalid) path
The build output was showing
Node found at: /var/folders/dy/bbm86qs502g4h1qx3dhrpyk40000gn/T/yarn--1706023232853-0.9009324729880421/node
and then failing on the next line:
<project-path>/ios/Pods/../../node_modules/react-native/ReactCommon/../scripts/react_native_pods_utils/script_phases.sh: line 34: /var/folders/dy/bbm86qs502g4h1qx3dhrpyk40000gn/T/yarn--1706023232853-0.9009324729880421/node: No such file or directory
Upvotes: 2
Reputation: 1233
The solution I used documented here, was to create a script at /usr/local/bin/node
that calls nvm
#!/usr/bin/env sh
# Use the version of node specified in .nvmrc to run the supplied command
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh" # This loads nvm
nvm_rc_version > /dev/null 2> /dev/null
HAS_NVM_RC=$?
if [[ "$HAS_NVM_RC" == "0" ]] ; then
nvm run $*
else
nvm run default $*
fi
exit $?
Upvotes: 0
Reputation: 966
Xcode have some issues finding node from nvm, try this inside the script that throws the error:
# Setup nvm and set node
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.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
[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"
$NODE_BINARY ../node_modules/@sentry/cli/bin/sentry-cli upload-dsym
Upvotes: 3
Reputation: 526
In my case, this was related to an old sentry configuration and the fact that I use nvm.
Following https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/
you should be able to execute ln -s $(which node) /usr/local/bin/node
and get it fixed
Upvotes: 1
Reputation: 1500
if you are using nvm do
sudo ln -s "$(which node)" /usr/local/bin/node
this will link current nvm to your usr local and next time Xcode will find the correct node path and version
Upvotes: 108
Reputation: 14610
Add this at the top of the script that's failing (in Project -> build phases):
. ~/.nvm/nvm.sh
Upvotes: 0
Reputation: 2500
Here is one of the solutions for this error if you're using nvm
and sentry
: https://docs.sentry.io/clients/react-native/manual-setup/#using-node-with-nvm
Upvotes: 4