Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.15.0 - Inaccurate error with "Looks like you installed react-native globally" #4515

Closed
niftylettuce opened this issue Dec 3, 2015 · 16 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@niftylettuce
Copy link
Contributor

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?

screen shot 2015-12-02 at 9 49 50 pm
screen shot 2015-12-02 at 9 48 22 pm

@niftylettuce
Copy link
Contributor Author

This is from a fresh react-native init.

@niftylettuce
Copy link
Contributor Author

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

@facebook-github-bot
Copy link
Contributor

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.

  • If this is a feature request or a bug that you would like to be fixed by the team, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • If you don't know how to do something or not sure whether some behavior is expected or a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • We welcome clear issues and PRs that are ready for in-depth discussion; thank you for your contributions!

@satya164
Copy link
Contributor

satya164 commented Dec 3, 2015

@niftylettuce Which package do you have installed globally? react-native or react-native-cli?

@niftylettuce
Copy link
Contributor Author

react native cli
On Dec 2, 2015 10:02 PM, "Satyajit Sahoo" notifications@github.com 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
#4515 (comment)
.

@ide
Copy link
Contributor

ide commented Dec 3, 2015

I can repro this too but not sure about the cause.

@niftylettuce
Copy link
Contributor Author

I think its because package.json loads node_modules/.bin as environment
commands to use
On Dec 2, 2015 11:16 PM, "James Ide" notifications@github.com wrote:

I can repro this too but not sure about the cause.


Reply to this email directly or view it on GitHub
#4515 (comment)
.

@altern8tif
Copy link

I'm getting the same error on npm@3.5.0 and react-native-cli@0.1.7

@gre
Copy link
Contributor

gre commented Dec 3, 2015

one workaround is to npm install --save-dev react-native-cli

@jjshammas
Copy link

@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.

@svkurowski
Copy link

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.

@satya164
Copy link
Contributor

cc @mkonicek

@mkonicek
Copy link
Contributor

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.

@wootwoot1234
Copy link

@mkonicek Thanks!

@kaminskypavel
Copy link

@mkonicek thanks for sharing!

@mirza99
Copy link

mirza99 commented Nov 8, 2017

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

@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests