Realm-js: node: command not found

Created on 31 Oct 2017  ·  17Comments  ·  Source: realm/realm-js

PhaseScriptExecution Download\ Core /Users/me/Library/Developer/Xcode/DerivedData/Ology-dyfbenzvbbghgeebclxmorqgivwr/Build/Intermediates.noindex/RealmJS.build/Debug-iphonesimulator/RealmJS.build/Script-F63FF2C51C12462600B3B8E0.sh
    cd /Users/me/project/node_modules/realm/src
    /bin/sh -c /Users/me/Library/Developer/Xcode/DerivedData/Ology-dyfbenzvbbghgeebclxmorqgivwr/Build/Intermediates.noindex/RealmJS.build/Debug-iphonesimulator/RealmJS.build/Script-F63FF2C51C12462600B3B8E0.sh

/Users/me/Library/Developer/Xcode/DerivedData/Ology-dyfbenzvbbghgeebclxmorqgivwr/Build/Intermediates.noindex/RealmJS.build/Debug-iphonesimulator/RealmJS.build/Script-F63FF2C51C12462600B3B8E0.sh: 
line 2: node: command not found
Command /bin/sh failed with exit code 127

I get this error on a current project that I installed on a new machine.

Node was installed through nvm
react-native 0.49.5
realm-js 2.0.2
Mac OS High Sierra
nvm ls

->       v8.8.1
default -> 8.8.1 (-> v8.8.1)
node -> stable (-> v8.8.1) (default)
stable -> 8.8 (-> v8.8.1) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> N/A)
lts/argon -> v4.8.5 (-> N/A)
lts/boron -> v6.11.5 (-> N/A)

When I run node on the command line, it works normally.

Any ideas?

O-Community T-Help

Most helpful comment

Oh, yeah sorry that's probably because when you run /bin/sh from your terminal it's picking up the PATH from the parent shell, which allows node to work.

Different approach then, try (from your usual terminal where node is working):

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

That should put a symlink to node somewhere in the PATH that sh uses. If it already exists, I'm stumped.

All 17 comments

Which version of Xcode do you use? How is your PATH set up inside Xcode?

Is nvm configured in the default shell (/bin/sh)?

@rh389 I see neither node nor nvm in /bin/sh.
@kneth Xode 9.0.1, where would I check the PATH setting in Xcode?

That'll be the problem then - nvm is per-shell so even though node is on the path from your usual shell, xcode (which just runs things under /bin/sh) can't see it. You can run echo $PATH from each shell to confirm that your usual shell has a node path (usually) under ~/.nvm/versions that /bin/sh doesn't show.

I'd recommend installing nvm into /bin/sh and setting its default node version to be the same as you're using elsewhere.

@rh389 tried nvm alias default node but same issue. Not sure how to follow your suggestion.

Open up your terminal and run the command /bin/sh to step into the system shell (the one xcode uses) - if you can fix node there, it'll be fixed for xcode too.

hmm ok, if I run /bin/sh and then node -v I do get a normal version number back. So it seems to be working there. Though the error in XCode remains.

Oh, yeah sorry that's probably because when you run /bin/sh from your terminal it's picking up the PATH from the parent shell, which allows node to work.

Different approach then, try (from your usual terminal where node is working):

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

That should put a symlink to node somewhere in the PATH that sh uses. If it already exists, I'm stumped.

@rh389 That worked. Thanks! Now, I'm kind of curious what will happen if I install a different node with nvm. Wonder if there is a kind of default I can link to. But that's academic. Right now, can move again! Thanks again.

Also, wonder where this would merit a document update.

nvm is usually before /usr/local/bin in PATH so if you change node version with nvm in your usual shell that should work fine, but Xcode will continue to use the symlinked (old) version. Running the above command again would bring Xcode back into line. AFAIK there’s no system/user default to point to because nvm is designed to be local to each shell. You could install node system-wide alongside nvm though if you wanted to have a “primary” version.

@rh389 Thanks for solving the issue.

I'm facing with this problem.
"react-native": "0.47.0"
"realm": "^2.0.13"
Xcode 9.2

When I run : ln -s $(which node) /usr/local/bin/node
=> ln: /usr/local/bin/node: File exists
How can I solve that

@bkitduy This has nothing to do with realm. Please ask on StackOverflow for general unix questions.

The easiest fix, which worked for me (everything else just compounded my errors) is to just go to https://nodejs.org/en/ and download latest copy of nodejs and install. Problem solved.

On OSX, I installed node@8 with homebrew which points to /usr/local/opt/node@8/bin/node instead of /usr/local/bin/node.

So ln -s $(which node) /usr/local/bin/node as written by @rh389 does the trick!

@rh389 you rock man! I got the same problem and that solved it! Thanks!

Any update on this?

ln -s $(which node) /usr/local/bin/node is bad, because it fixes the node version on /usr/local/bin/node.

When using NVM, the goal is that the version of the node is not fixed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

laznrbfe picture laznrbfe  ·  3Comments

ugendrang picture ugendrang  ·  3Comments

jmartindivmedianet picture jmartindivmedianet  ·  3Comments

ashah888 picture ashah888  ·  3Comments

camslaz picture camslaz  ·  4Comments