Skip to content

[nextjs] sourceMappingURL comment is not stripped from Turbopack worker chunks when deleteSourcemapsAfterUpload is enabled #25874

Closed

Description

@macchiitaka

Is there an existing issue for this?

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

  1. Use the config above in a Next.js 16 app that creates a Web Worker with new Worker(new URL(..., import.meta.url)).
  2. Run next build (Turbopack) with SENTRY_AUTH_TOKEN set, so that source maps are uploaded.
  3. Inspect the end of .next/static/chunks/turbopack-worker-<hash>.js (or the copied file in out/).

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:

  1. Upload: @sentry/bundler-plugins calls sentry sourcemap upload (sentry CLI 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 _sentryDebugIds snippet and appends \n//# debugId=<id>\n after the existing sourceMappingURL comment.
  2. Strip: stripSourceMappingURLComments uses a regex anchored to the end of the file, so it no longer matches once //# debugId= follows the sourceMappingURL comment.

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

  1. linear-code commented on Oct 29, 2026

    @linear-code
  2. self-assigned this
    on Oct 29, 2026
  3. msonnb commented on Oct 29, 2026

    @msonnb
    Member

    Hey @macchiitaka, thanks for reporting! The fix will be included in our next release.

  4. macchiitaka commented on Oct 29, 2026

    @macchiitaka
    Author

    Thanks @msonnb for the quick fix in #25881! I'll verify it on our build after the next release.

  5. added a commit that references this issue on Oct 29, 2026
    f7b6364
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions