Skip to content

Commit b1c0faa

Browse files
levriktrueadm
authored andcommitted
Show warning when trying to run on port below 1024 without admin permissions under Linux (#2518)
1 parent 2ab7ead commit b1c0faa

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

packages/react-dev-utils/WebpackDevServerUtils.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const path = require('path');
1414
const url = require('url');
1515
const chalk = require('chalk');
1616
const detect = require('detect-port-alt');
17+
const isRoot = require('is-root');
1718
const inquirer = require('inquirer');
1819
const clearConsole = require('./clearConsole');
1920
const formatWebpackMessages = require('./formatWebpackMessages');
@@ -378,14 +379,19 @@ function choosePort(host, defaultPort) {
378379
if (port === defaultPort) {
379380
return resolve(port);
380381
}
382+
const message = process.platform !== 'win32' &&
383+
defaultPort < 1024 &&
384+
!isRoot()
385+
? `Admin permissions are required to run a server on a port below 1024.`
386+
: `Something is already running on port ${defaultPort}.`;
381387
if (isInteractive) {
382388
clearConsole();
383389
const existingProcess = getProcessForPort(defaultPort);
384390
const question = {
385391
type: 'confirm',
386392
name: 'shouldChangePort',
387393
message: chalk.yellow(
388-
`Something is already running on port ${defaultPort}.` +
394+
message +
389395
`${existingProcess ? ` Probably:\n ${existingProcess}` : ''}`
390396
) + '\n\nWould you like to run the app on another port instead?',
391397
default: true,
@@ -398,9 +404,7 @@ function choosePort(host, defaultPort) {
398404
}
399405
});
400406
} else {
401-
console.log(
402-
chalk.red(`Something is already running on port ${defaultPort}.`)
403-
);
407+
console.log(chalk.red(message));
404408
resolve(null);
405409
}
406410
}),

packages/react-dev-utils/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"gzip-size": "3.0.0",
4545
"html-entities": "1.2.1",
4646
"inquirer": "3.0.6",
47+
"is-root": "1.0.0",
4748
"opn": "5.0.0",
4849
"recursive-readdir": "2.2.1",
4950
"shell-quote": "1.6.1",

0 commit comments

Comments
 (0)