17

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

Almog
  • 2,639
  • 6
  • 30
  • 59
  • Got it working by following the following - https://stackoverflow.com/questions/43465086/env-node-no-such-file-or-directory-in-mac – Almog Mar 01 '18 at 01:36

6 Answers6

84

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

Luis
  • 1,242
  • 11
  • 18
  • 1
    just to confirm this was the solution for me in July 2021 - xcode 12.5.1 – Jonatas CD Jul 27 '21 at 12:17
  • 3
    This is a great solution. Just one thing to keep in mind: it will specifically set the version of Node that XCode knows about to the one you currently have activated. If you ever switch versions of node using NVM, you should re-run this command so that XCode is symlinked to that same version – Robert Townley Oct 20 '21 at 14:56
  • This is the right answer, on xcode 13. Caused by xcode not being able to find node (nvm) – Desmond Jan 09 '22 at 13:21
  • Right answer for me too! It's also written in the readme file =) – Don Diego Feb 03 '22 at 15:45
  • Late to the party but this doesn't work for me: I'm getting the following error: ln: /user/local/bin/node: No such file or directory. Anyone that can help me out? – Brent Le Comte Aug 23 '22 at 10:05
  • This worked for me, Xcode 13.3.1 and react-native version 0.70.5. – Shreyak Upadhyay Nov 15 '22 at 06:27
  • This worked for me, Xcode 14.2 React Native 0.68.3 – Huan Huynh Jan 06 '23 at 02:19
  • Works for me too. XCode version 14.2 – aldok Feb 06 '23 at 14:40
  • 1
    @BrentLeComte, please confirm you have the required .xcode.env.local file without any typos. Then confirm your currently used version of Node matches what you specified in that file. Double-check for typos. Try replacing it's contents with this if all else fails: `export NODE_BINARY=$(command -v node)` – Jibreel Keddo Feb 08 '23 at 23:54
  • 1
    @JibreelKeddo thanks for the response! It was indeed something to do with Node but as it has been almost half a year I kinda forgot what it was. – Brent Le Comte Feb 10 '23 at 09:31
3

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

user2976753
  • 935
  • 11
  • 24
  • This solution worked for me running React Native >= 0.60 with sentry-react-native version 1.7.2. Navigate to Build Phases --> Bundle React Native code and images – Brian Li Sep 04 '20 at 05:57
2

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

Huy Vo
  • 2,418
  • 6
  • 22
  • 43
1

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

0

Add this at the top of the script that's failing (in Project -> build phases):

. ~/.nvm/nvm.sh
Andreas Bergström
  • 13,891
  • 5
  • 59
  • 53
0

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 $?
Nigel
  • 1,203
  • 2
  • 11
  • 20