From 3e25ccd7bd32ebf0e32db81ce68ea502de267345 Mon Sep 17 00:00:00 2001 From: s1gr1d <32902192+s1gr1d@users.noreply.github.com> Date: Tue, 13 Oct 2026 14:11:49 +0200 Subject: [PATCH] fix(nuxt): Keep sourcesContent in Nuxt 5 server source maps Nitro's source map minification runs after the bundler writes the maps. On Nitro 3 it deletes sourcesContent, which overrides the module's sourcemapExcludeSources: false. Set nitro.experimental.sourcemapMinify to false so Sentry can show the server source. Fixes #25322 --- .../test-applications/nuxt-5-sourcemaps/assert-build.ts | 6 +++--- packages/nuxt/src/vite/sourceMaps.ts | 7 +++++-- packages/nuxt/test/vite/sourceMaps.test.ts | 9 +++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/nuxt-5-sourcemaps/assert-build.ts b/dev-packages/e2e-tests/test-applications/nuxt-5-sourcemaps/assert-build.ts index 5bf988c300ad..0a86f401f470 100644 --- a/dev-packages/e2e-tests/test-applications/nuxt-5-sourcemaps/assert-build.ts +++ b/dev-packages/e2e-tests/test-applications/nuxt-5-sourcemaps/assert-build.ts @@ -162,9 +162,9 @@ const containsMarker = (marker: string): boolean => // Vite builds the client and Nitro builds the server. Counting bundles would still pass with either // plugin dropped, so each side is pinned to a marker only that side's source supplies. assert.ok(containsMarker(CLIENT_MARKER), 'Expected an uploaded sourcemap carrying the client source (Vite plugin)'); -// TODO: Nitro 3 builds the server with Rolldown, and the uploaded server maps carry no `sourcesContent`: the -// module's `sourcemapExcludeSources: false` does not reach that build. Assert the server marker when that is fixed: -// assert.ok(containsMarker(SERVER_MARKER), 'Expected an uploaded sourcemap carrying the server source (Rollup plugin)'); +// Nitro 3 deletes `sourcesContent` from the server maps unless `experimental.sourcemapMinify` is `false`. The module +// sets it to `false`, which is the only reason this marker survives into `sourcesContent`. +assert.ok(containsMarker(SERVER_MARKER), 'Expected an uploaded sourcemap carrying the server source (Rollup plugin)'); // `rewriteSources` normalizes `../../../foo` to `./foo` so paths stay resolvable in Sentry. const unnormalizedSources = [...new Set(sourcemaps.flatMap(map => map.sourcemap.sources ?? []))].filter( diff --git a/packages/nuxt/src/vite/sourceMaps.ts b/packages/nuxt/src/vite/sourceMaps.ts index 5d0f634fac59..94cae5a3f506 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -324,7 +324,7 @@ export function changeNuxtSourceMapSettings( } /** Logs warnings about potentially conflicting source map settings. - * Configures `sourcemapExcludeSources` in Nitro to make source maps usable in Sentry. + * Configures `sourcemapExcludeSources` and `sourcemapMinify` in Nitro to make source maps usable in Sentry. * * only exported for testing */ @@ -364,10 +364,13 @@ export function validateNitroSourceMapSettings( } nitroConfig.rollupConfig.output.sourcemapExcludeSources = false; + // Nitro's source map minification runs after the bundler wrote the maps: it clears `mappings` of maps with + // `node_modules` sources, and Nitro 3 also deletes `sourcesContent`, which overrides `sourcemapExcludeSources`. + nitroConfig.experimental = { ...nitroConfig.experimental, sourcemapMinify: false }; if (isDebug) { // eslint-disable-next-line no-console console.log( - '[Sentry] Set `sourcemapExcludeSources: false` in the Nuxt config (`nitro.rollupConfig.output`). Source maps will now include the actual code to be able to un-minify code snippets in Sentry.', + '[Sentry] Set `sourcemapExcludeSources: false` (`nitro.rollupConfig.output`) and `sourcemapMinify: false` (`nitro.experimental`) in the Nuxt config. Source maps will now include the actual code to be able to un-minify code snippets in Sentry.', ); } } diff --git a/packages/nuxt/test/vite/sourceMaps.test.ts b/packages/nuxt/test/vite/sourceMaps.test.ts index 443b4b9d9a8f..db00688a14d1 100644 --- a/packages/nuxt/test/vite/sourceMaps.test.ts +++ b/packages/nuxt/test/vite/sourceMaps.test.ts @@ -328,6 +328,7 @@ describe('validate sourcemap settings', () => { rollupConfig?: { output?: { sourcemap?: SourceMapSetting; sourcemapExcludeSources?: boolean }; }; + experimental?: { asyncContext?: boolean; sourcemapMinify?: false }; }; type MinimalNuxtConfig = { options: { sourcemap?: SourceMapSetting | { server?: SourceMapSetting; client?: SourceMapSetting } }; @@ -363,6 +364,14 @@ describe('validate sourcemap settings', () => { expect(nitroConfig?.rollupConfig?.output?.sourcemapExcludeSources).toBe(false); }); + it("should disable Nitro's source map minification and keep other experimental options", () => { + const nitroConfig = { ...getNitroConfig(true), experimental: { asyncContext: true } }; + + validateNitroSourceMapSettings(getNuxtConfig(true), nitroConfig, { debug: true }); + + expect(nitroConfig.experimental).toEqual({ asyncContext: true, sourcemapMinify: false }); + }); + it('should not show console.warn when rollup sourcemap is undefined', () => { const nitroConfig = getNitroConfig(true);