Skip to content

Commit f4b2d21

Browse files
franticFacebook Github Bot 7
authored andcommitted
Fix usage of react-native cli inside package.json scripts
Summary: IIRC we made `wrong-react-native` to warn people in case they installed `react-native` globally (instead of `react-native-cli` what the guide suggests). To do that we added `bin` entry to React Native's `package.json` that points to `local-cli/wrong-react-native.js` However, this means that if we have a project that uses `react-native` package and has call to `react-native` CLI inside its package.json, npm will execute *local* override (which just prints a confusing in this context error message). In fact, the template we generate with `react-native init` has `react-native start` as `start` script, which makes it useless. Let's fix it by making `wrong-react-native` script smarter – it can detect that it has been executed from local `node_modules` and run the actual CLI. cc vjeux ide Closes facebook/react-native#7243 Differential Revision: D3226645 Pulled By: frantic fb-gh-sync-id: be094eb0e70e491da4ebefc2abf11cff56c4c5b7 fbshipit-source-id: be094eb0e70e491da4ebefc2abf11cff56c4c5b7
1 parent 5a069d9 commit f4b2d21

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

wrong-react-native.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99
* of patent rights can be found in the PATENTS file in the same directory.
1010
*/
1111

12-
console.error([
13-
'\033[31mLooks like you installed react-native globally, maybe you meant react-native-cli?',
14-
'To fix the issue, run:\033[0m',
15-
'npm uninstall -g react-native',
16-
'npm install -g react-native-cli'
17-
].join('\n'));
12+
var script = process.argv[1];
13+
var installedGlobally = script.indexOf('node_modules/.bin/react-native') === -1;
1814

19-
process.exit(1);
15+
if (installedGlobally) {
16+
console.error([
17+
'\033[31mLooks like you installed react-native globally, maybe you meant react-native-cli?',
18+
'To fix the issue, run:\033[0m',
19+
'npm uninstall -g react-native',
20+
'npm install -g react-native-cli'
21+
].join('\n'));
22+
process.exit(1);
23+
} else {
24+
require('./cli').run();
25+
}

0 commit comments

Comments
 (0)