From d68ed30f2cf9e441c4324eee03b6ea041c9b72e7 Mon Sep 17 00:00:00 2001 From: Levin Rickert Date: Mon, 19 Jun 2017 18:00:11 +0200 Subject: [PATCH] Show warning when trying to run on port below 1024 without admin permissions under Linux (#2518) --- packages/react-dev-utils/WebpackDevServerUtils.js | 12 ++++++++---- packages/react-dev-utils/package.json | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/react-dev-utils/WebpackDevServerUtils.js b/packages/react-dev-utils/WebpackDevServerUtils.js index ab1991d8c..1e1113c18 100644 --- a/packages/react-dev-utils/WebpackDevServerUtils.js +++ b/packages/react-dev-utils/WebpackDevServerUtils.js @@ -14,6 +14,7 @@ const path = require('path'); const url = require('url'); const chalk = require('chalk'); const detect = require('detect-port-alt'); +const isRoot = require('is-root'); const inquirer = require('inquirer'); const clearConsole = require('./clearConsole'); const formatWebpackMessages = require('./formatWebpackMessages'); @@ -378,6 +379,11 @@ function choosePort(host, defaultPort) { if (port === defaultPort) { return resolve(port); } + const message = process.platform !== 'win32' && + defaultPort < 1024 && + !isRoot() + ? `Admin permissions are required to run a server on a port below 1024.` + : `Something is already running on port ${defaultPort}.`; if (isInteractive) { clearConsole(); const existingProcess = getProcessForPort(defaultPort); @@ -385,7 +391,7 @@ function choosePort(host, defaultPort) { type: 'confirm', name: 'shouldChangePort', message: chalk.yellow( - `Something is already running on port ${defaultPort}.` + + message + `${existingProcess ? ` Probably:\n ${existingProcess}` : ''}` ) + '\n\nWould you like to run the app on another port instead?', default: true, @@ -398,9 +404,7 @@ function choosePort(host, defaultPort) { } }); } else { - console.log( - chalk.red(`Something is already running on port ${defaultPort}.`) - ); + console.log(chalk.red(message)); resolve(null); } }), diff --git a/packages/react-dev-utils/package.json b/packages/react-dev-utils/package.json index 9a7a61119..6fa6c4117 100644 --- a/packages/react-dev-utils/package.json +++ b/packages/react-dev-utils/package.json @@ -44,6 +44,7 @@ "gzip-size": "3.0.0", "html-entities": "1.2.1", "inquirer": "3.0.6", + "is-root": "1.0.0", "opn": "5.0.0", "recursive-readdir": "2.2.1", "shell-quote": "1.6.1",