diff --git a/.changeset/stupid-dryers-bow.md b/.changeset/stupid-dryers-bow.md new file mode 100644 index 000000000..9224e66ee --- /dev/null +++ b/.changeset/stupid-dryers-bow.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +nit: ask user to modify devOptions.port when addr in use for dev diff --git a/packages/astro/src/dev.ts b/packages/astro/src/dev.ts index fdebc72cb..f6a765ba4 100644 --- a/packages/astro/src/dev.ts +++ b/packages/astro/src/dev.ts @@ -101,9 +101,18 @@ export default async function dev(astroConfig: AstroConfig) { }); const port = astroConfig.devOptions.port; - server.listen(port, hostname, () => { - const endServerTime = performance.now(); - info(logging, 'dev server', green(`Server started in ${Math.floor(endServerTime - startServerTime)}ms.`)); - info(logging, 'dev server', `${green('Local:')} http://${hostname}:${port}/`); - }); + server + .listen(port, hostname, () => { + const endServerTime = performance.now(); + info(logging, 'dev server', green(`Server started in ${Math.floor(endServerTime - startServerTime)}ms.`)); + info(logging, 'dev server', `${green('Local:')} http://${hostname}:${port}/`); + }) + .on('error', (err: NodeJS.ErrnoException) => { + if (err.code && err.code === 'EADDRINUSE') { + error(logging, 'dev server', `Address ${hostname}:${port} already in use. Try changing devOptions.port in your config file`); + } else { + error(logging, 'dev server', err.stack); + } + process.exit(1); + }); }