Skip to content

Commit 26a6dd2

Browse files
logaretmclaude
andcommitted
fix(nitro): Handle non-boolean sourcemap values ('hidden', 'inline')
Nitro types `sourcemap` as `boolean`, but the value is forwarded to Vite which also accepts `'hidden'` and `'inline'`. The previous logic treated any non-`true`/`false` value as unset and overwrote it with `'hidden'` plus default deletion, which (1) clobbered an explicit `'inline'` choice and (2) auto-deleted `.map` files the user had configured via `'hidden'`. Now we keep `'hidden'` and `true` as-is (upload, no deletion), warn and skip upload for `'inline'` (no `.map` files exist to upload), and only enable hidden + deletion when `sourcemap` is unset. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3f30c9a commit 26a6dd2

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

packages/nitro/src/sourceMaps.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function shouldSkipSourcemapUpload(nitro: Nitro, options?: SentryNitroOptions):
2626
nitro.options.dev ||
2727
nitro.options.preset === 'nitro-prerender' ||
2828
nitro.options.sourcemap === false ||
29+
(nitro.options.sourcemap as unknown) === 'inline' ||
2930
options?.sourcemaps?.disable === true
3031
);
3132
}
@@ -141,23 +142,35 @@ export function configureSourcemapSettings(
141142
return { sentryEnabledSourcemaps: false };
142143
}
143144

144-
if (config.sourcemap === false) {
145+
// Nitro types `sourcemap` as `boolean`, but it forwards the value to Vite which also accepts `'hidden'` and `'inline'`.
146+
const userSourcemap = (config as { sourcemap?: boolean | 'hidden' | 'inline' }).sourcemap;
147+
148+
if (userSourcemap === false) {
145149
// eslint-disable-next-line no-console
146150
console.warn(
147151
'[@sentry/nitro] You have explicitly disabled source maps (`sourcemap: false`). Sentry will not upload source maps, and errors will not be unminified. To let Sentry handle source maps, remove the `sourcemap` option from your Nitro config, or use `sourcemaps: { disable: true }` in your Sentry options to silence this warning.',
148152
);
149153
return { sentryEnabledSourcemaps: false };
150154
}
151155

156+
if (userSourcemap === 'inline') {
157+
// eslint-disable-next-line no-console
158+
console.warn(
159+
'[@sentry/nitro] You have set `sourcemap: "inline"`. Inline source maps are embedded in the output bundle, so there are no `.map` files to upload. Sentry will not upload source maps. Set `sourcemap: "hidden"` (or leave it unset) to let Sentry upload source maps and un-minify errors.',
160+
);
161+
return { sentryEnabledSourcemaps: false };
162+
}
163+
152164
let sentryEnabledSourcemaps = false;
153-
if (config.sourcemap === true) {
165+
if (userSourcemap === true || userSourcemap === 'hidden') {
154166
if (moduleOptions?.debug) {
155167
// eslint-disable-next-line no-console
156-
console.log('[@sentry/nitro] Source maps are already enabled. Sentry will upload them for error unminification.');
168+
console.log(
169+
`[@sentry/nitro] Source maps are already enabled (\`sourcemap: ${JSON.stringify(userSourcemap)}\`). Sentry will upload them for error unminification.`,
170+
);
157171
}
158172
} else {
159173
// User did not explicitly set sourcemap, enable hidden source maps for Sentry.
160-
// Nitro types `sourcemap` as `boolean`, but it forwards the value to Vite which supports `'hidden'`.
161174
// `'hidden'` emits .map files without adding a `//# sourceMappingURL=` comment to the output, avoiding public exposure.
162175
(config as { sourcemap?: unknown }).sourcemap = 'hidden';
163176
sentryEnabledSourcemaps = true;

packages/nitro/test/sourceMaps.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,25 @@ describe('configureSourcemapSettings', () => {
215215
expect(result.sentryEnabledSourcemaps).toBe(false);
216216
});
217217

218+
it('keeps sourcemap "hidden" when user already set it and does not enable deletion', () => {
219+
const config = { sourcemap: 'hidden' } as unknown as NitroConfig;
220+
const result = configureSourcemapSettings(config);
221+
222+
expect((config as { sourcemap?: unknown }).sourcemap).toBe('hidden');
223+
expect(result.sentryEnabledSourcemaps).toBe(false);
224+
});
225+
226+
it('keeps sourcemap "inline", warns, and does not enable uploads', () => {
227+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
228+
const config = { sourcemap: 'inline' } as unknown as NitroConfig;
229+
const result = configureSourcemapSettings(config);
230+
231+
expect((config as { sourcemap?: unknown }).sourcemap).toBe('inline');
232+
expect(result.sentryEnabledSourcemaps).toBe(false);
233+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('`sourcemap: "inline"`'));
234+
warnSpy.mockRestore();
235+
});
236+
218237
it('disables experimental sourcemapMinify', () => {
219238
const config: NitroConfig = {};
220239
configureSourcemapSettings(config);

0 commit comments

Comments
 (0)