-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
add pretty message if port already in use(#927) #932
Changes from 3 commits
0efd6f9
30e77d1
d675deb
cb9b3b3
9f6ccce
f55b901
8de2b51
9404483
0278e8b
6d7945c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,10 @@ srv.start(argv.port) | |
} | ||
}) | ||
.catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
if (err.code === 'EADDRINUSE') { | ||
console.error(`Port ${argv.port} is already in use.\nUse \`npm run dev -- -p <some other port>\`.`) | ||
} else { | ||
console.error(err) | ||
} | ||
process.nextTick(function () { process.exit(1) }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, it was a long day 😉 |
||
reject(error) | ||
}) | ||
this.http.on('listening', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
resolve() | ||
}) | ||
this.http.listen(port, () => {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can omit callback ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems it's optional https://nodejs.org/api/http.html#http_server_listen_handle_callback |
||
}) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not 100% sure, the user will have
dev
NPM script for next. So, we should try to find it.Find a NPM script with just
next
but not withnext start
ornext build
.If we found it, add the message which says
npm run <script name> -- -p <some other port>
.Otherwise, just don't display that.