Repository navigation
[nextjs] sourceMappingURL comment is not stripped from Turbopack worker chunks when deleteSourcemapsAfterUpload is enabled #25874
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases (using 11.8.0; the relevant code is unchanged on
develop, see Additional Context)
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
11.8.0
Framework Version
Next 16.4.2 (Turbopack production build)
Link to Sentry event
No response
Reproduction Example/SDK Setup
// next.config.ts
import { withSentryConfig } from '@sentry/nextjs/config'
export default withSentryConfig(
{
output: 'export',
productionBrowserSourceMaps: true,
},
{
org: '<org>',
project: '<project>',
authToken: process.env.SENTRY_AUTH_TOKEN,
sourcemaps: {
deleteSourcemapsAfterUpload: true,
},
},
)The app creates a Web Worker with new Worker(new URL('./worker', import.meta.url)), so Turbopack emits a worker bootstrap chunk (static/chunks/turbopack-worker-<hash>.js).
Steps to Reproduce
- Use the config above in a Next.js 16 app that creates a Web Worker with
new Worker(new URL(..., import.meta.url)). - Run
next build(Turbopack) withSENTRY_AUTH_TOKENset, so that source maps are uploaded. - Inspect the end of
.next/static/chunks/turbopack-worker-<hash>.js(or the copied file inout/).
Expected Result
All sourceMappingURL comments are removed from the client JS after the source maps are uploaded and deleted, as with every other chunk.
Actual Result
The worker bootstrap chunk still ends with a sourceMappingURL comment that points to a deleted .map file:
;!function(){try{var e=...;e._sentryDebugIds[n]="<debug-id>",e._sentryDebugIdIdentifier="sentry-dbid-<debug-id>")}catch(e){}}();
!function(){ /* Turbopack worker bootstrap */ }();
//# sourceMappingURL=<hash>.js.map
//# debugId=<debug-id>All other chunks are stripped correctly. Without SENTRY_AUTH_TOKEN, the upload does not run and the comment is stripped, so the issue only appears in builds that actually upload source maps.
Additional Context
This seems to be caused by two steps that run in this order in handleRunAfterProductionCompile:
- Upload:
@sentry/bundler-pluginscallssentry sourcemap upload(sentryCLI 0.45.0) without--no-rewrite. For JS files that have neither a//# debugId=comment nor a debug ID in their source map, the CLI injects a debug ID in place. It prepends the_sentryDebugIdssnippet and appends\n//# debugId=<id>\nafter the existingsourceMappingURLcomment.- https://github.com/getsentry/cli/blob/3567c3c937b5cc06667d5b023bda0b2d3f472c54/packages/cli/src/lib/sourcemap/debug-id.ts#L230
- Turbopack's native debug IDs (
turbopack.debugIds) are added to regular chunks, but not to the worker bootstrap chunk, so only this chunk gets injected by the CLI.
- Strip:
stripSourceMappingURLCommentsuses a regex anchored to the end of the file, so it no longer matches once//# debugId=follows thesourceMappingURLcomment.sentry-javascript/packages/nextjs/src/config/handleRunAfterProductionCompile.ts
Lines 98 to 100 in 90c1ebb
if (deleteSourcemapsAfterUpload && buildTool === 'turbopack' && !sriEnabled) { await stripSourceMappingURLComments(path.join(distDir, 'static'), sentryBuildOptions); } const SOURCEMAPPING_URL_COMMENT_REGEX = /(?:^|\n)\/\/[#@] sourceMappingURL=[^\s'"`*]+\s*$/;
The relevant code is unchanged on develop of sentry-javascript and in sentry CLI 0.47.0 (the CLI still appends //# debugId= after existing content).
A possible fix is to make the strip regex tolerate trailing //# debugId= comments (or remove sourceMappingURL comments regardless of position in the trailing comment block).
Activity
linear-code commentedon Oct 29, 2026
JS-4035
msonnb commentedon Oct 29, 2026
Hey @macchiitaka, thanks for reporting! The fix will be included in our next release.
macchiitaka commentedon Oct 29, 2026
Thanks @msonnb for the quick fix in #25881! I'll verify it on our build after the next release.
fix(nextjs): Strip source map comments before trailing debug IDs (get…