Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 270fe06

Browse filesBrowse files
authored
Catch synchronous errors from spawning yarn (facebook#1204)
* Catch synchronous errors from spawning yarn * Fix issues
1 parent 0a9865d commit 270fe06
Copy full SHA for 270fe06

File tree

1 file changed

+30
-19
lines changed
Filter options

1 file changed

+30
-19
lines changed

‎packages/create-react-app/index.js

Copy file name to clipboardExpand all lines: packages/create-react-app/index.js
+30-19Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,37 +108,48 @@ function createApp(name, verbose, version) {
108108
}
109109

110110
function install(packageToInstall, verbose, callback) {
111-
var args = [
111+
function fallbackToNpm() {
112+
var npmArgs = [
113+
'install',
114+
verbose && '--verbose',
115+
'--save-dev',
116+
'--save-exact',
117+
packageToInstall,
118+
].filter(function(e) { return e; });
119+
var npmProc = spawn('npm', npmArgs, {stdio: 'inherit'});
120+
npmProc.on('close', function (code) {
121+
callback(code, 'npm', npmArgs);
122+
});
123+
}
124+
125+
var yarnArgs = [
112126
'add',
113127
'--dev',
114128
'--exact',
115129
packageToInstall,
116130
];
117-
var proc = spawn('yarn', args, {stdio: 'inherit'});
118-
131+
var yarnProc;
119132
var yarnExists = true;
120-
proc.on('error', function (err) {
133+
try {
134+
yarnProc = spawn('yarn', yarnArgs, {stdio: 'inherit'});
135+
} catch (err) {
136+
// It's not clear why we end up here in some cases but we need this.
137+
// https://github.com/facebookincubator/create-react-app/issues/1200
138+
yarnExists = false;
139+
fallbackToNpm();
140+
return;
141+
}
142+
yarnProc.on('error', function (err) {
121143
if (err.code === 'ENOENT') {
122144
yarnExists = false;
123145
}
124146
});
125-
proc.on('close', function (code) {
147+
yarnProc.on('close', function (code) {
126148
if (yarnExists) {
127-
callback(code, 'yarn', args);
128-
return;
149+
callback(code, 'yarn', yarnArgs);
150+
} else {
151+
fallbackToNpm();
129152
}
130-
// No Yarn installed, continuing with npm.
131-
args = [
132-
'install',
133-
verbose && '--verbose',
134-
'--save-dev',
135-
'--save-exact',
136-
packageToInstall,
137-
].filter(function(e) { return e; });
138-
var npmProc = spawn('npm', args, {stdio: 'inherit'});
139-
npmProc.on('close', function (code) {
140-
callback(code, 'npm', args);
141-
});
142153
});
143154
}
144155

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.