Node: better serverEntrypoint error (#5560)

* fix(node): better entrypoint error

* fix(node): surface start errors during preview

Co-authored-by: Nate Moore <nate@astro.build>
This commit is contained in:
Nate Moore 2022-12-08 15:54:19 -05:00 committed by GitHub
parent 02bb0a1ccd
commit 281ea9fc34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/node': patch
---
Improve error message when serverEntrypoint does not exist

View file

@ -24,10 +24,14 @@ const preview: CreatePreviewServer = async function ({
`The server entrypoint doesn't have a handler. Are you sure this is the right file?`
);
}
} catch (_err) {
throw new Error(
`The server entrypoint ${fileURLToPath} does not exist. Have you ran a build yet?`
);
} catch (err) {
if ((err as any).code === 'ERR_MODULE_NOT_FOUND') {
throw new Error(
`The server entrypoint ${fileURLToPath(serverEntrypoint)} does not exist. Have you ran a build yet?`
);
} else {
throw err;
}
}
const handler: http.RequestListener = (req, res) => {