Skip to content

Commit e280254

Browse files
authored
Handle errors from port detector (#2182)
1 parent 46eeabc commit e280254

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

packages/react-scripts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"react-scripts": "./bin/react-scripts.js"
2222
},
2323
"dependencies": {
24-
"@timer/detect-port": "1.1.2",
24+
"@timer/detect-port": "1.1.3",
2525
"address": "1.0.1",
2626
"autoprefixer": "7.1.0",
2727
"babel-core": "6.24.1",

packages/react-scripts/scripts/start.js

+35-26
Original file line numberDiff line numberDiff line change
@@ -140,33 +140,42 @@ function run(port) {
140140

141141
// We attempt to use the default port but if it is busy, we offer the user to
142142
// run on a different port. `detect()` Promise resolves to the next free port.
143-
detect(DEFAULT_PORT, HOST).then(port => {
144-
if (port === DEFAULT_PORT) {
145-
run(port);
146-
return;
147-
}
143+
detect(DEFAULT_PORT, HOST).then(
144+
port => {
145+
if (port === DEFAULT_PORT) {
146+
run(port);
147+
return;
148+
}
148149

149-
if (isInteractive) {
150-
clearConsole();
151-
const existingProcess = getProcessForPort(DEFAULT_PORT);
152-
const question = {
153-
type: 'confirm',
154-
name: 'shouldChangePort',
155-
message: chalk.yellow(
156-
`Something is already running on port ${DEFAULT_PORT}.` +
157-
`${existingProcess ? ` Probably:\n ${existingProcess}` : ''}`
158-
) + '\n\nWould you like to run the app on another port instead?',
159-
default: true,
160-
};
161-
162-
inquirer.prompt(question).then(answer => {
163-
if (answer.shouldChangePort) {
164-
run(port);
165-
}
166-
});
167-
} else {
150+
if (isInteractive) {
151+
clearConsole();
152+
const existingProcess = getProcessForPort(DEFAULT_PORT);
153+
const question = {
154+
type: 'confirm',
155+
name: 'shouldChangePort',
156+
message: chalk.yellow(
157+
`Something is already running on port ${DEFAULT_PORT}.` +
158+
`${existingProcess ? ` Probably:\n ${existingProcess}` : ''}`
159+
) + '\n\nWould you like to run the app on another port instead?',
160+
default: true,
161+
};
162+
163+
inquirer.prompt(question).then(answer => {
164+
if (answer.shouldChangePort) {
165+
run(port);
166+
}
167+
});
168+
} else {
169+
console.log(
170+
chalk.red(`Something is already running on port ${DEFAULT_PORT}.`)
171+
);
172+
}
173+
},
174+
err => {
168175
console.log(
169-
chalk.red(`Something is already running on port ${DEFAULT_PORT}.`)
176+
chalk.red(`Could not find an open port at ${chalk.bold(HOST)}.`)
170177
);
178+
console.log('Network error message: ' + err.message || err);
179+
console.log();
171180
}
172-
});
181+
);

0 commit comments

Comments
 (0)