I've bootstrapped a new react-native project with the latest react-native-cli and when I try to run it in XCode, I get:
../node_modules/react-native/packager/react-native-xcode.sh: line 36: react-native: command not found
_That means I can not anymore run a react-native 0.14 app in my system._
So if I understand this correctly, XCode is calling a shell script. But I'm using nvm and my react-native is not global (unless executing some env files), so I guess xcode don't execute my env? Also i'm using ZSH.
I feel that the packager should not expect react-native command to exist because it really depend on the env config of each developer and we will likely have a lot of issues like this.
Why is there a strong dependency from react-native packager to react-native-cli ? Someone that fork a react-native example/project should be able to just _run_ it without having to install react-native-cli separately
Workaround: create a
~/.profilethat setup the environment and add. ~/.profileat the beginning of./node_modules/react-native/packager/react-native-xcode.sh.. Unfortunately I don't see a way to setup this in XCode.
Having the same story right now. can you explain your ~/.profile setup and the corresponding line 36 ff in react-native-xcode.sh ? would be great, I am lost here .... :-/
In my ~/.profile:
export NVM_DIR="/Users/gre/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm use node
and, i'm prepending in ./node_modules/react-native/packager/react-native-xcode.sh:
. ~/.profile
This is a temporary "hack" that is definitely not viable.
thx for input. will try later ...
:+1: I have the same issue
Me with the same issue
Despite the React Native docs recommending nvm, it's a terrible solution for any automation environment since it requires a shell running its injected functions to operate. I describe that in more detail on a comment on related issue 3948.
ndenv would be an ideal alternative here, but there's apparently a bug in Xcode 7 that is preventing adding directories to the PATH used for custom build scripts. The only workaround I've found so far is to install node to /usr/local via homebrew temporarily until a better solution becomes available.
+1
+1
+1
At the end solved by adding
source ~/.bash_profile
to ../myproject/node_modules/react-native/packager/react-native-xcode.sh
thx to https://github.com/ilarip
+1 I did add the path to ~/.profile but still see the same issue. I restarted xcode to make sure the changes are reflected but no luck.
@magizh have you also modified node_modules/react-native/packager/react-native-xcode.sh ?
That's a really fragile solution for now..
@jwhitley: Unfortunately I don't think we should ask all users to migrate to another tool or hack the node environment... this will be a terrible thing that everyone will complain about, especially that things used to work until RN 0.14 broke it. I feel this is fixable, react-native is able to start a npm start so why not this? (I'm wondering if this feature has been introduced for copying assets and why npm start is not enough?)
I was also looking in setting the $PATH for XCode but as you said, it doesn't seem to work..
Cheers
@gre I understand the difficulty, but the very tool that the React Native documentation recommended (nvm) is _actively hostile to automation_. It installs node, npm, and the bin scripts in a way that is not on PATH nor has any sane, canonical way for a script to determine the correct location of executables.
I'll be less politic than in my other posts: _nvm and rvm should be considered harmful_. These tools embody a terrible pattern to inflict on software developers, who ever more rely on automating their workflows. Consider that users will be using a variety of approaches to installing node: nvm, ndenv, homebrew, distro packages, etc. Only one of these is not like the others, in that it completely eschews PATH: nvm.
If someone works out a scheme that lets react-native-xcode.sh somehow do the right thing and doesn't break non-nvm users, then great, more power to them. But my own experiences suggest that it's better in the long-term to absorb the pain now and make the transition to calling dependencies on PATH. (Of course, Xcode may have its own ideas about that... :sob:)
@jwhitley if you have a suggestion for a Node installation system other than nvm we could consider it. The requirements are: lets you control multiple versions of Node, doesn't require sudo when installing Node or global npm packages, is well documented on the internet in general (ex: stack overflow). As far as I am aware nvm is by far the most popular solution for managing Node versions and works for a very large number of people so voicing your concerns to the nvm maintainers could be the best outcome for the community at large.
@ide I recommend ndenv, which is the node equivalent of Ruby's rbenv. It meets all of those requirements, excepting the StackOverflow point. But it works well, is actively maintained, and robust. ndenv version installs are fast, as it directly queries and installs node's official upstream builds for your platform.
I was one of a number of folks involved years ago in trying to get the rvm folks to switch away from injecting shell functions, but the maintainers had simply no comprehension of or desire to change the problems with their existing system. Perhaps a discussion with the nvm team might go better, but I don't hold out much hope, since that suggestion is almost literally "throw away your codebase, fork and rename ndenv".
@jwhitley thanks for the pointer. I'll keep it on my radar screen. If nvm becomes unmaintanable we certainly can look at ndenv closely. For now I'd like to get things working for nvm users (since there are a lot of them) while not breaking things for non-nvm users as you point out :)
@gre I added 'source ~/.profile' to the .sh file. Now it works thanks. I assumed restarting the xcode would fix read the latest profile file.
Please try react-native 0.14.2, which should include a fix for this.
mine is 0.14.2, but the issue is still happening
But it works after sourcing from .profile and .bash_profile in react-native-xcode.sh
Me too. Same error in 0.14.2
Adding source ~/.bash_profile in react-native-xcode.sh works though.
0.14.2 same error with node 4.2.0
still having the error
Still getting this error, 0.14.2 react, node 4.2.0
Added source ~/.bash_profile to .sh file
still no luck
Did you install node with NVM, i.e. do you have a ~/.nvm (hidden) folder?
@Thorbenandresen I do. And also in homebrew, should I uninstall this?
@Thorbenandresen I just looked inside of ~/bin for sh and the file doesn't exsist, should it?
And in my .bash_profile I have
source ~/.nvm/nvm.sh
My current error message - scroll to bottom for expected error code
https://gist.github.com/lendyme/3ce419513262d29e68a6
@lendyme ok see if you still have nvm installed by typing nvm --version. If not, installed it as described here: https://github.com/creationix/nvm. Once installed, install node with nvm install 5.1 (or whatever version you need).
This worked for me (even without the need to source the ~/.bash_profile), so maybe it works for you as well. My problem was that I had a incompatible old node version installed with NVM but the current version via the web installer. Although node -v would return 5.1.1, Xcode was still using the old NVM version when it was compiling the project.
@Thorbenandresen how do I confirm what version of NVM xcode is using?
Installed new version of node via nvm and still not luck :(
@lendyme I dont know, sorry. I assumed that it Xcode would use the NVM node version because, I got the exact same error upon npm start when I uninstalled my non-NVM node version.
It confuses me when owners/contributors close issues like this one when they clearly aren't resolved. :(
But anyway, I also had to add source ~/.bash_profile to ./node_modules/react-native/packager/react-native-xcode.sh to fix it.
My node is installed in a custom directory. Adding source ~/.bash_profile fixed the problem but gets tedious when you have to npm install a lot.
A more persistent solution is to prefix the command with the path to your node installation in Xcode like this:
PATH=$PATH:/path/to/node/bin ../node_modules/react-native/packager/react-native-xcode.sh
Still a hack though.
My nvm location is /usr/local/var/nvm, but it is trying to looking for nvm at ~/.nvm.
Any suggestions?
This is a good solution for now if you use nvm: ln -s /Users/zach/.nvm/versions/node/v5.3.0/lib/node_modules/* /usr/local/lib/node_modules @chapinkapa
Oh! Of course. Good idea. Although another solution would be better for react-native in general.
Sent from my iPhone
On Dec 19, 2015, at 4:41 PM, Zach Silveira [email protected] wrote:
This is a good solution for now if you use nvm: ln -s /Users/zach/.nvm/versions/node/v5.3.0/lib/node_modules/* /usr/local/lib/node_modules @chapinkapa
—
Reply to this email directly or view it on GitHub.
I am not using nvm because I have an alternate nodejs prefix, and nvm would not install unless I removed that from my nodejs install, and used the 'standard' prefix. I used the alternate prefix for a reason, so I didn't want to conform to nvm's limitations.
I saw that several people were advocating modifications to react-native-xcode.sh in order to resolve the missing path issue. I was not comfortable doing that.. but I noticed that that sources ~/.nvm/nvm.sh if it exists.
So, while I'm not using nvm, I did create ~/.nvm and ~/.nvm.nvm.sh. And, I just added the required path elements there.
echo "Calling my home-made nvm.sh"
export PATH=$PATH:/usr/local/bin:~/npm-global/bin
That is all I needed to resolve the errors finding react-native, and node. No need to touch the node_modules files, and things work for me now.
What happens if you have fish shell ;)
I run this and fix it
Mac OS
Wade$ nvm ls
v0.10.29
v0.10.32
v0.10.40
v0.12.2
v4.2.3
-> system
nvm use v4.2.3,
It's because that the version of node , It requires Node Version > 4.0
I followed the steps provided on Getting Started and encountered the same issue.
nvm 0.30.1
node v5.4.1
npm 3.5.3
Go to your terminal and type which node.
On Jan 19, 2016, at 8:13 AM, Naveen babu E [email protected] wrote:
I followed the steps provided on Getting Started and encountered the same issue.
nvm 0.30.1
node v5.4.1
npm 3.5.3—
Reply to this email directly or view it on GitHub.
I installed nvm in /usr/local. Node is installed at /usr/local/nvm-latest/versions/node/v5.4.1/bin/node. I was able to get past the problem by following @coderdave solution. I saw that this issue was closed, but did not solve the problem.
add source ~/.bash_profile to ./node_modules/react-native/packager/react-native-xcode.sh to fix it.
The packager is going to look at ~/nvm. You can do this:
ln -s ~/.nvm /usr/local/nvm
I have solved this problem by adding lines:
. ~/.nvm/nvm.sh
nvm use node
to Xcode build settings in 'Build Phases' -> 'Bundle React Native code and images' right before
../node_modules/react-native/packager/react-native-xcode.sh
My solution is simple if you're using nvm:
Run nvm alias default node because each time a new Terminal comes about, it was defaulting to system node.
I came up with the following simple solution:
$ npm install -g react-native-cli
/Users/kris/npm/bin/react-native -> /Users/kris/npm/lib/node_modules/react-native-cli/index.js
/Users/kris/npm/lib
└── [email protected]
ls /Users/kris/npm
I confirm there is a /bin folder with the react-native binary inside...
I then manually added /Users/kris/npm/bin to my $PATH
export PATH=$PATH:/usr/local/bin/:/Users/kris/npm/bin
IT WORKS!!!
I had this project before Android feature came out, and my .xcodeproj is outside the iOS folder.
If this is the case for you and you are manually adding
../node_modules/react-native/packager/react-native-xcode.sh
into your Build Phases.
make sure you first change it to
./node_modules/react-native/packager/react-native-xcode.sh
and inside react-native-xcode.sh
remove the line cd ..
Going into build phases in xcode and deleting the last entry with the word images worked for me.
Try to do this: $ npm install -g react-native-cli
This fixed my issue
Wrote a full solution here: http://stackoverflow.com/a/39607966/4523369
@kristianmandrup
it works! thank you so much.
@kristianmandrup like:
$ sudo npm install -g react-native-cli
/Users/burak/.npm-packages/bin/react-native -> /Users/burak/.npm-packages/lib/node_modules/react-native-cli/index.js
/Users/burak/.npm-packages/lib
└── [email protected]
ls /Users/burak/.npm-packages
Warning .npm-packages
Its worked trying this code: export PATH=$PATH:/Users/burak/.npm-packages/bin/
@kristianmandrup
it works! thank you so much.
Most helpful comment
Try to do this:
$ npm install -g react-native-cliThis fixed my issue