Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions packages/nuxt/src/vite/sourceMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.',
);
}
}
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 @@ -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 } };
Expand Down Expand Up @@ -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);

Expand Down
Loading