Permalink
Browse files

Gracefully handle if port is busy when starting dev server (#1198)

Also inform which process is using the port. Partially based on #1013. Closes #897
  • Loading branch information...
oscar-b authored and MoOx committed Nov 10, 2017
1 parent 3c76fd6 commit ac792d5bba85cbf73be9d01e9a68a73b2b8d2619
Showing with 258 additions and 52 deletions.
  1. +1 −0 packages/core/package.json
  2. +17 −1 packages/core/src/commands/start.js
  3. +240 −51 yarn.lock
@@ -29,6 +29,7 @@
"mkdirp": "^0.5.1",
"p-map": "^1.2.0",
"path-to-regexp": "^1.7.0",
"react-dev-utils": "^4.2.1",
"rimraf": "^2.5.4",
"sane": "^1.7.0",
"simple-json-fetch": "^1.0.1",
@@ -2,6 +2,8 @@ import path from "path";
import express from "express";
import socketIO from "socket.io";
import getProcessForPort from "react-dev-utils/getProcessForPort";
import chalk from "chalk";
import createWatcher from "../watch";
import processFile from "../injection/processFile";
@@ -106,7 +108,21 @@ async function start(config: PhenomicConfig) {
);
}
});
bundlerServer.listen(config.port);
bundlerServer.listen(config.port).on("error", err => {
if (err.errno === "EADDRINUSE") {
const existingProcess = getProcessForPort(err.port);
log(
chalk.yellow(
`Something is already running on port ${err.port}. ${existingProcess
? `Probably:\n${existingProcess}\n`
: ""}`
)
);
} else {
log(err);
}
process.exit(1);
});
console.log(`✨ Open http://localhost:${config.port}`);
}
Oops, something went wrong.

0 comments on commit ac792d5

Please sign in to comment.