Skip to content

Commit

Permalink
Node: better serverEntrypoint error (#5560)
Browse files Browse the repository at this point in the history
* fix(node): better entrypoint error

* fix(node): surface start errors during preview

Co-authored-by: Nate Moore <nate@astro.build>
  • Loading branch information
natemoo-re and natemoo-re committed Dec 8, 2022
1 parent 02bb0a1 commit 281ea9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-pens-lie.md
@@ -0,0 +1,5 @@
---
'@astrojs/node': patch
---

Improve error message when serverEntrypoint does not exist
12 changes: 8 additions & 4 deletions packages/integrations/node/src/preview.ts
Expand Up @@ -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) => {
Expand Down

0 comments on commit 281ea9f

Please sign in to comment.