Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/nuxt/src/vite/sourceMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.',
);
}
}
Expand Down
9 changes: 9 additions & 0 deletions packages/nuxt/test/vite/sourceMaps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } };
Expand Down Expand Up @@ -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);

Expand Down
Loading