realm-js: node: command not found

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?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 18 (8 by maintainers)

Most upvoted comments

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.

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!

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.

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.

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.