From 6dfd7081b7a1532ab0fe3af8bcf079b10a5640a9 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Tue, 27 Jun 2023 21:16:29 +0800 Subject: [PATCH] Fix error stacktrace from Vite SSR runtime (#7273) --- .changeset/breezy-onions-scream.md | 5 +++++ packages/astro/src/vite-plugin-astro-postprocess/index.ts | 2 +- packages/astro/src/vite-plugin-astro-server/request.ts | 6 ++++++ packages/astro/src/vite-plugin-env/index.ts | 2 +- packages/astro/src/vite-plugin-scripts/page-ssr.ts | 2 +- 5 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 .changeset/breezy-onions-scream.md diff --git a/.changeset/breezy-onions-scream.md b/.changeset/breezy-onions-scream.md new file mode 100644 index 000000000000..706a09c22b21 --- /dev/null +++ b/.changeset/breezy-onions-scream.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix error stacktrace from Vite SSR runtime diff --git a/packages/astro/src/vite-plugin-astro-postprocess/index.ts b/packages/astro/src/vite-plugin-astro-postprocess/index.ts index 05895ab627c7..96735f2cb194 100644 --- a/packages/astro/src/vite-plugin-astro-postprocess/index.ts +++ b/packages/astro/src/vite-plugin-astro-postprocess/index.ts @@ -61,7 +61,7 @@ export default function astro(_opts: AstroPluginOptions): Plugin { if (s) { return { code: s.toString(), - map: s.generateMap(), + map: s.generateMap({ hires: true }), }; } }, diff --git a/packages/astro/src/vite-plugin-astro-server/request.ts b/packages/astro/src/vite-plugin-astro-server/request.ts index adf4199d1638..3c5da0575b67 100644 --- a/packages/astro/src/vite-plugin-astro-server/request.ts +++ b/packages/astro/src/vite-plugin-astro-server/request.ts @@ -81,6 +81,12 @@ export async function handleRequest( }, onError(_err) { const err = createSafeError(_err); + + // This could be a runtime error from Vite's SSR module, so try to fix it here + try { + env.loader.fixStacktrace(err as Error); + } catch {} + // This is our last line of defense regarding errors where we still might have some information about the request // Our error should already be complete, but let's try to add a bit more through some guesswork const errorWithMetadata = collectErrorMetadata(err, config.root); diff --git a/packages/astro/src/vite-plugin-env/index.ts b/packages/astro/src/vite-plugin-env/index.ts index 1f21696e30e9..8d5a9c1c3df8 100644 --- a/packages/astro/src/vite-plugin-env/index.ts +++ b/packages/astro/src/vite-plugin-env/index.ts @@ -137,7 +137,7 @@ export default function envVitePlugin({ settings }: EnvPluginOptions): vite.Plug if (s) { return { code: s.toString(), - map: s.generateMap(), + map: s.generateMap({ hires: true }), }; } }, diff --git a/packages/astro/src/vite-plugin-scripts/page-ssr.ts b/packages/astro/src/vite-plugin-scripts/page-ssr.ts index 97fdf3b59550..82fc12761f96 100644 --- a/packages/astro/src/vite-plugin-scripts/page-ssr.ts +++ b/packages/astro/src/vite-plugin-scripts/page-ssr.ts @@ -35,7 +35,7 @@ export default function astroScriptsPostPlugin({ return { code: s.toString(), - map: s.generateMap(), + map: s.generateMap({ hires: true }), }; }, };