Fix error stacktrace from Vite SSR runtime (#7273)

This commit is contained in:
Bjorn Lu 2023-06-27 21:16:29 +08:00 committed by GitHub
parent 83016795e9
commit 6dfd7081b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix error stacktrace from Vite SSR runtime

View file

@ -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 }),
};
}
},

View file

@ -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);

View file

@ -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 }),
};
}
},

View file

@ -35,7 +35,7 @@ export default function astroScriptsPostPlugin({
return {
code: s.toString(),
map: s.generateMap(),
map: s.generateMap({ hires: true }),
};
},
};