diff options
author | 2023-06-27 21:16:29 +0800 | |
---|---|---|
committer | 2023-06-27 21:16:29 +0800 | |
commit | 6dfd7081b7a1532ab0fe3af8bcf079b10a5640a9 (patch) | |
tree | fc7aaef0a89a7e8161041f91f6453c8dd9dd5995 | |
parent | 83016795e9e149bc64e2441d477cf8c65ef5a117 (diff) | |
download | astro-6dfd7081b7a1532ab0fe3af8bcf079b10a5640a9.tar.gz astro-6dfd7081b7a1532ab0fe3af8bcf079b10a5640a9.tar.zst astro-6dfd7081b7a1532ab0fe3af8bcf079b10a5640a9.zip |
Fix error stacktrace from Vite SSR runtime (#7273)
5 files changed, 14 insertions, 3 deletions
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 }), }; }, }; |