From b24d47a5bab46a1b8096187ad43a4c42349919c2 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2026 07:39:56 +0000 Subject: [PATCH] fix(v10/nuxt): Keep sourcesContent in Nuxt 5 server source maps Backport of: #25325 --- packages/nuxt/src/vite/sourceMaps.ts | 7 +++++-- packages/nuxt/test/vite/sourceMaps.test.ts | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/vite/sourceMaps.ts b/packages/nuxt/src/vite/sourceMaps.ts index 5a6000e51b2b..21132dfc33f6 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -332,7 +332,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 */ @@ -372,10 +372,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 aa7056e775f1..45997b8298cd 100644 --- a/packages/nuxt/test/vite/sourceMaps.test.ts +++ b/packages/nuxt/test/vite/sourceMaps.test.ts @@ -427,6 +427,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 } }; @@ -462,6 +463,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);