Skip to content

Commit 3f30c9a

Browse files
logaretmclaude
andcommitted
fix(nitro): Default to hidden source maps when Sentry enables them
Previously when users didn't set `sourcemap`, we set it to `true`, which causes Nitro/Vite to append `//# sourceMappingURL=` to each output file, publicly exposing sourcemap references. Switch to `'hidden'` so .map files are still emitted (and uploaded/deleted by Sentry) without the public reference comment. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 36ddac0 commit 3f30c9a

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

packages/nitro/src/sourceMaps.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,15 @@ export function configureSourcemapSettings(
156156
console.log('[@sentry/nitro] Source maps are already enabled. Sentry will upload them for error unminification.');
157157
}
158158
} else {
159-
// User did not explicitly set sourcemap — enable it for Sentry
160-
config.sourcemap = true;
159+
// 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'`.
161+
// `'hidden'` emits .map files without adding a `//# sourceMappingURL=` comment to the output, avoiding public exposure.
162+
(config as { sourcemap?: unknown }).sourcemap = 'hidden';
161163
sentryEnabledSourcemaps = true;
162164
if (moduleOptions?.debug) {
163165
// eslint-disable-next-line no-console
164166
console.log(
165-
'[@sentry/nitro] Enabled source map generation for Sentry. Source map files will be deleted after upload.',
167+
'[@sentry/nitro] Enabled hidden source map generation for Sentry. Source map files will be deleted after upload.',
166168
);
167169
}
168170
}

packages/nitro/test/sourceMaps.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ describe('getPluginOptions', () => {
179179
});
180180

181181
describe('configureSourcemapSettings', () => {
182-
it('enables sourcemap generation on the config', () => {
182+
it('enables hidden sourcemap generation on the config', () => {
183183
const config: NitroConfig = {};
184184
const result = configureSourcemapSettings(config);
185185

186-
expect(config.sourcemap).toBe(true);
186+
expect(config.sourcemap).toBe('hidden');
187187
expect(result.sentryEnabledSourcemaps).toBe(true);
188188
});
189189

@@ -244,7 +244,7 @@ describe('configureSourcemapSettings', () => {
244244
const config: NitroConfig = {};
245245
configureSourcemapSettings(config, { sourcemaps: { disable: 'disable-upload' } });
246246

247-
expect(config.sourcemap).toBe(true);
247+
expect(config.sourcemap).toBe('hidden');
248248
});
249249
});
250250

0 commit comments

Comments
 (0)