diff --git a/.changeset/breezy-onions-scream.md b/.changeset/breezy-onions-scream.md new file mode 100644 index 000000000..706a09c22 --- /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 05895ab62..96735f2cb 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 adf4199d1..3c5da0575 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 1f21696e3..8d5a9c1c3 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 97fdf3b59..82fc12761 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 }), }; }, };