Skip to content

Handle errors from port detector #2182

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

Merged
merged 1 commit into from
May 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-scripts/package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
"react-scripts": "./bin/react-scripts.js"
},
"dependencies": {
"@timer/detect-port": "1.1.2",
"@timer/detect-port": "1.1.3",
"address": "1.0.1",
"autoprefixer": "7.1.0",
"babel-core": "6.24.1",
61 changes: 35 additions & 26 deletions packages/react-scripts/scripts/start.js
Original file line number Diff line number Diff line change
@@ -140,33 +140,42 @@ function run(port) {

// We attempt to use the default port but if it is busy, we offer the user to
// run on a different port. `detect()` Promise resolves to the next free port.
detect(DEFAULT_PORT, HOST).then(port => {
if (port === DEFAULT_PORT) {
run(port);
return;
}
detect(DEFAULT_PORT, HOST).then(
port => {
if (port === DEFAULT_PORT) {
run(port);
return;
}

if (isInteractive) {
clearConsole();
const existingProcess = getProcessForPort(DEFAULT_PORT);
const question = {
type: 'confirm',
name: 'shouldChangePort',
message: chalk.yellow(
`Something is already running on port ${DEFAULT_PORT}.` +
`${existingProcess ? ` Probably:\n ${existingProcess}` : ''}`
) + '\n\nWould you like to run the app on another port instead?',
default: true,
};

inquirer.prompt(question).then(answer => {
if (answer.shouldChangePort) {
run(port);
}
});
} else {
if (isInteractive) {
clearConsole();
const existingProcess = getProcessForPort(DEFAULT_PORT);
const question = {
type: 'confirm',
name: 'shouldChangePort',
message: chalk.yellow(
`Something is already running on port ${DEFAULT_PORT}.` +
`${existingProcess ? ` Probably:\n ${existingProcess}` : ''}`
) + '\n\nWould you like to run the app on another port instead?',
default: true,
};

inquirer.prompt(question).then(answer => {
if (answer.shouldChangePort) {
run(port);
}
});
} else {
console.log(
chalk.red(`Something is already running on port ${DEFAULT_PORT}.`)
);
}
},
err => {
console.log(
chalk.red(`Something is already running on port ${DEFAULT_PORT}.`)
chalk.red(`Could not find an open port at ${chalk.bold(HOST)}.`)
);
console.log('Network error message: ' + err.message || err);
console.log();
}
});
);