[0.15] react-native upgrade: Cannot find module 'opn'
I updated the version of react-native under dependencies to 0.15.0 and ran
npm install
And when I run
react-native upgrade
I got a problem:
Error: Cannot find module 'opn'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/Users/tianchishao/native/HotelCtrl/node_modules/react-native/local-cli/server/middleware/getDevToolsMiddleware.js:13:11)
at Module._compile (module.js:435:26)
at normalLoader (/Users/tianchishao/native/HotelCtrl/node_modules/babel-core/lib/api/register/node.js:199:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/tianchishao/native/HotelCtrl/node_modules/babel-core/lib/api/register/node.js:216:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
How should I do to upgrade my project to 0.15.0?
Hey mjhlybmwq, 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, please ask on StackOverflow with the tag
react-nativeor for more real time interactions, ask on Discord in the #react-native channel. - We welcome well-written issues and PRs that are ready for in-depth discussion; thank you for your contributions!
Thanks a lot for reporting this @mjhlybmwq!
It might be a bug in react-native upgrade. I'll take a look. You can upgrade manually - for iOS you don't need to do anything, for Android you just need to change this line in android/app/build.gradle:
compile "com.facebook.react:react-native:0.15.+
Can you try rm -rf node_modules and install again? What does node --version print? For me it's 4.2.1.
react-native upgrade works after rm -rf node_modules and npm install.
However, npm start no longer works. What I get is something like this:
Looks like you installed react-native globally, maybe you meant react-native-cli? To fix the issue, run: npm uninstall -g react-native npm install -g react-native-cli
But when I try react-native start, it works. Should I open a new issue?
The version of node for me is 5.0.0/4.2.2(I use n).
@mjhlybmwq Can you post your package.json file?
Ensure that you have the following,
...
"scripts": {
"start": "node_modules/react-native/packager/packager.sh"
},
...
Also, running npm uninstall -g react-native && npm install -g react-native-cli solve your issue.
my package.json:
{
"name": "HotelCtrl",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start"
},
"dependencies": {
"react-native": "^0.15.0",
"react-native-carousel": "^0.4.2",
"react-native-side-menu": "^0.14.4",
"react-native-vector-icons": "^0.8.4"
}
}
I'm wondering what's the difference between npm start and react-native start
In your case, npm start runs the react-native start command. You can change react-native start in your package.json to node_modules/react-native/packager/packager.sh.
Does this solve your issue?
Of course it does. But it's wired that an npm script differs from a command in terminal. In my case, npm start does not behave as the same as react-native start. Any ideas?
Did you run npm uninstall -g react-native && npm install -g react-native-cli ?
No, I didn't. I want to figure out what's wrong before I run it.
The react-native-cli package provides the react-native command. The react-native package provides the library files. You don't have the correct package installed globally.
I know. But it does not explain that react-native start works well.
What's more, after I ran npm uninstall -g react-native && npm install -g react-native-cli, I still get the same message, which is wierd. I've checked \usr\local\lib\node_modules\ and there's no react-native. There's only react-native-cli.
@mjhlybmwq Obviously, the package name is react-native-cli. The react-native command will be under /usr/local/bin/.
Yes, I got the command as expect but the script npm start still doesn't run the command.
@mjhlybmwq There might be something wrong with your path. The preferred way is to run node_modules/react-native/packager/packager.sh from npm start, as it doesn't require a global dependency, and everything is self contained in your project folder.
First of all, thank you for your attention and your solution.
npm start, which runs react-native start command, works well with my another project which uses RN 0.14.2. I wonder there might be something wrong in the latest package.
@mjhlybmwq You're welcome