Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup of React Native using ndenv on OS X

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:

  • How do I correctly append to PATH for a custom build script in Xcode 7?
  • Alternatively, what's the best (least hacky?) way of getting ndenv-managed npm modules on PATH for the build script?

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.

like image 428
John Whitley Avatar asked Sep 26 '22 06:09

John Whitley


2 Answers

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:

  • https://github.com/facebook/react-native/issues/3974
  • https://github.com/facebook/react-native/issues/3948

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.shbefore 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. )

like image 57
Lukas Reichart Avatar answered Sep 28 '22 22:09

Lukas Reichart


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

like image 29
LaSean Smith Avatar answered Sep 28 '22 22:09

LaSean Smith