diff --git a/packages/nextjs/src/config/handleRunAfterProductionCompile.ts b/packages/nextjs/src/config/handleRunAfterProductionCompile.ts index d5c90962e581..901ba9dffa6e 100644 --- a/packages/nextjs/src/config/handleRunAfterProductionCompile.ts +++ b/packages/nextjs/src/config/handleRunAfterProductionCompile.ts @@ -50,7 +50,8 @@ export async function handleRunAfterProductionCompile( await sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal(); await sentryBuildPluginManager.createRelease(); - if (!usesNativeDebugIds) { + // Skip debug ID injection if sourcemaps are disabled which are only relevant for sourcemap correlation + if (!usesNativeDebugIds && sentryBuildOptions.sourcemaps?.disable !== true) { await sentryBuildPluginManager.injectDebugIds([distDir]); } diff --git a/packages/nextjs/test/config/handleRunAfterProductionCompile.test.ts b/packages/nextjs/test/config/handleRunAfterProductionCompile.test.ts index f32eb28ddcfc..2d1769986158 100644 --- a/packages/nextjs/test/config/handleRunAfterProductionCompile.test.ts +++ b/packages/nextjs/test/config/handleRunAfterProductionCompile.test.ts @@ -249,6 +249,62 @@ describe('handleRunAfterProductionCompile', () => { }); }); + describe('sourcemaps disabled', () => { + it('skips debug ID injection when sourcemaps.disable is true', async () => { + const optionsWithDisabledSourcemaps: SentryBuildOptions = { + ...mockSentryBuildOptions, + sourcemaps: { + disable: true, + }, + }; + + await handleRunAfterProductionCompile( + { + releaseName: 'test-release', + distDir: '/path/to/.next', + buildTool: 'turbopack', + }, + optionsWithDisabledSourcemaps, + ); + + expect(mockSentryBuildPluginManager.injectDebugIds).not.toHaveBeenCalled(); + expect(mockSentryBuildPluginManager.uploadSourcemaps).toHaveBeenCalled(); + }); + + it('still injects debug IDs when sourcemaps.disable is false', async () => { + const optionsWithEnabledSourcemaps: SentryBuildOptions = { + ...mockSentryBuildOptions, + sourcemaps: { + disable: false, + }, + }; + + await handleRunAfterProductionCompile( + { + releaseName: 'test-release', + distDir: '/path/to/.next', + buildTool: 'turbopack', + }, + optionsWithEnabledSourcemaps, + ); + + expect(mockSentryBuildPluginManager.injectDebugIds).toHaveBeenCalledWith(['/path/to/.next']); + }); + + it('still injects debug IDs when sourcemaps option is undefined', async () => { + await handleRunAfterProductionCompile( + { + releaseName: 'test-release', + distDir: '/path/to/.next', + buildTool: 'turbopack', + }, + mockSentryBuildOptions, + ); + + expect(mockSentryBuildPluginManager.injectDebugIds).toHaveBeenCalledWith(['/path/to/.next']); + }); + }); + describe('path handling', () => { it('correctly passes distDir to debug ID injection', async () => { const customDistDir = '/custom/dist/path';