diff --git a/bin/next-dev b/bin/next-dev index 0df5f875292c5..3584aab3e92b9 100755 --- a/bin/next-dev +++ b/bin/next-dev @@ -61,6 +61,10 @@ srv.start(argv.port) } }) .catch((err) => { - console.error(err) + if (err.code === 'EADDRINUSE') { + console.error(`Port ${argv.port} is already in use.\nUse \`npm run dev -- -p \`.`) + } else { + console.error(err) + } process.exit(1) }) diff --git a/server/index.js b/server/index.js index 494e4422b2bd5..129ca6c778015 100644 --- a/server/index.js +++ b/server/index.js @@ -119,10 +119,13 @@ export default class Server { await this.prepare() this.http = http.createServer(this.getRequestHandler()) await new Promise((resolve, reject) => { - this.http.listen(port, (err) => { - if (err) return reject(err) + this.http.on('error', (error) => { + reject(error) + }) + this.http.on('listening', () => { resolve() }) + this.http.listen(port, () => {}) }) }