Seems to be an odd bug when running with npm start vs. react-native start (perhaps due to it using react-native from the ./node_modules/.bin/react-native folder?


This is from a fresh react-native init.
You can also see I don't have it installed globally per the recommended uninstallation of global package (so this is why I mention it is inaccurate).
Hey niftylettuce, thanks for reporting this issue!
React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.
react-native or for more real time interactions, ask on Discord in the #react-native channel.@niftylettuce Which package do you have installed globally? react-native or react-native-cli?
react native cli
On Dec 2, 2015 10:02 PM, "Satyajit Sahoo" [email protected] wrote:
@niftylettuce https://github.com/niftylettuce Which package do you have
installed globally? react-native or react-native-cli?—
Reply to this email directly or view it on GitHub
https://github.com/facebook/react-native/issues/4515#issuecomment-161501922
.
I can repro this too but not sure about the cause.
I think its because package.json loads node_modules/.bin as environment
commands to use
On Dec 2, 2015 11:16 PM, "James Ide" [email protected] wrote:
I can repro this too but not sure about the cause.
—
Reply to this email directly or view it on GitHub
https://github.com/facebook/react-native/issues/4515#issuecomment-161510215
.
I'm getting the same error on [email protected] and [email protected]
one workaround is to npm install --save-dev react-native-cli
@gre thank you so much for that workaround. Fixed the issue for me.
I'm only seeing this problem when building on a Mac via Jenkins. Not locally on any dev machine.
Okay, some steps to reproduce (Mac OS X 10.11.2, npm 3.5.2, nodejs 5.3.0).
cd /tmp
npm install -g react-native-cli
react-native init test
cd test
ls -l /usr/local/bin | grep react # react-native -> ../lib/node_modules/react-native-cli/index.js
ls -l node_modules/.bin | grep react # react-native -> ../react-native/local-cli/wrong-react-native.js
npm run start # Looks like you installed react-native globally, maybe you meant react-native-cli?
This happens because npm prepends node_modules/.bin to the PATH environment variable.
As suggested above we try to fix this:
npm install --save-dev react-native-cli
ls -l /usr/local/bin | grep react # react-native -> ../lib/node_modules/react-native-cli/index.js
# bingo, it's working
However, will this also work on a fresh machine?
rm -Rf node_modules
npm install
ls -l node_modules/.bin | grep react # react-native -> ../react-native/local-cli/wrong-react-native.js
# Oops, not working again
At this moment, package.json looks like this:
{
"name": "test",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start"
},
"dependencies": {
"react-native": "^0.18.0-rc"
},
"devDependencies": {
"react-native-cli": "^0.1.10"
}
}
Remove react-native-cli from the devDependencies and insert it before react-native as a normal dependency like this:
"dependencies": {
"react-native-cli": "^0.1.10",
"react-native": "^0.18.0-rc"
}
Then run
rm -Rf node_modules
npm install
ls -l /usr/local/bin | grep react # react-native -> ../lib/node_modules/react-native-cli/index.js
# bingo, it's working
Putting react-native-cli after react-native does also not work. The binary names from react-native-cli and react-native have a conflict, apparently npm prefers the on from the first listed normal (non-dev) dependency.
So until this gets fixed, the only reliable way seems to be to either list react-native-cli before react-native in the dependencies (however I don't know whether this behavior of npm is undefined) or install react-native-cli globally and run react-native start instead of npm run start.
cc @mkonicek
npm start is defined in your package.json, "start": "react-native start" is wrong due to a bug I introduced in an older version of the global CLI, please change that to:
{
"name": "MyApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"react-native": "rn_version_you_are_using"
}
}
The new global CLI will generate package.json like that, sorry about the breakage!
To upgrade:
npm uninstall -g react-native-cli
npm install -g react-native-cli
(and fix package.json for all your apps)
If this doesn't resolve the issue let's reopen.
I don't understand why "react-native-cli" would be in the dependencies or dev dependencies of your app. Your app doesn't need the CLI.
@mkonicek Thanks!
@mkonicek thanks for sharing!
I had the same issue even after uninstalling react-native and react-native-cli. When looking in /usr/local/lib/node_modules there was no react-native-*
I use nvm so the modules was installed under ~/.nvm/versions/node/v8.0.0/bin/ (you have to look in your currently used version). Hope it helps
Most helpful comment
one workaround is to
npm install --save-dev react-native-cli