I'm running into PATH difficulty setting up a new React Native iOS project in Xcode 7.1. I'm trying to use ndenv
to manage node versions, which means ~/.ndenv/shims
needs to be on PATH. To that end, I have PATH set as a user-defined project setting as $PATH:~/.ndenv/shims
. The Xcode settings UI shows the correct expanded PATH value.
Yet the project, generated by react-native init
, still fails to build. The custom build script fails to find react-native
:
../node_modules/react-native/packager/react-native-xcode.sh: line 36: react-native: command not found
react-native
is installed correctly, but the environment variables dump in the build output makes clear that ~/.ndenv/shims
isn't on PATH. My PATH settings don't appear in the build environment. However, if I set a random user-defined setting (e.g. FOOBAR=baz
), that does correctly show up in the build environment.
That result plus further inspection of PATH in the build environment makes clear that Xcode is overriding PATH somewhere along the line.
So in order of preference:
Modifying react-native-xcode.sh is out of the question, since that's a part of the external react-native npm module.
UPDATE 1
As a temporary workaround, I've bailed on ndenv and installed node via homebrew. This puts react-native
on the (apparently-hardcoded) Xcode path at /usr/local/bin
, and works to get the build running. I'm not going to submit or accept this as a solution, since it doesn't allow the repeatable control of node versions that ndenv does.
The problem seems to be that the react-native-xcode.sh
script depends on the react-native-cli
package to be in PATH. This issue was reported to the project in these two issues on Github:
I expect a fix to be implemented quite soon, because this is a major problem for anyone using the react-native cli to create new projects.
There are a few work arounds for this problem, but none of them are perfect. Which one would work for you depends on your node / npm setup:
I myself installed node via nvm and just needed to add export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
before running the react-native-xcode.sh
.
For this to work you need to have react-native-cli
installed globally.
If you need help finding a solution for your specific setup, please give me some more information about your node setup. ( or you can try one of the other solutions pointed out in the issues I linked above. )
Had the same issue. The work around called out in the link below is working for me. Haven't found a permanent solution.
The XCode $PATH differs from terminal $PATH and it doesn't include path of nvm nodes (~/.nvm/versions/...). This can be temporarily fixed by adding source ~/.bash_profile to the beginig of react-native-xcode.sh
https://github.com/facebook/react-native/issues/3948
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With