Skip to content

sourcemap inject/upload doesn't recognize a debug ID snippet minified to template literals and shifts Vite 8 chunks one line #2248

Done

Description

@n00dle

Environment

  • sentry 0.49.0, via @sentry/vite-plugin / @sentry/bundler-plugins 11.12.0
  • Vite 8.3.8 (Rolldown, Oxc minifier), build.sourcemap: true
  • The same check is on main at cc90ca1

Summary

Every frame from a Vite 8 build resolves one generated line off in Sentry.

The bundler plugin injects its debug ID snippet in renderChunk, and Vite 8's minifier then rewrites the snippet's string literals as template literals:

e._sentryDebugIds[t]=`4f39e3c4-c308-4c2e-8975-3241d12fbeef`,e._sentryDebugIdIdentifier=`sentry-dbid-4f39e3c4-c308-4c2e-8975-3241d12fbeef`

The plugin then uploads with sourcemap.upload, which runs inject first. DEBUGID_REGISTRATION_RE only matches a value quoted with " or ':

...\\s*=\\s*(["'])(${DEBUGID_PATTERN})\\1

so the CLI doesn't see the existing registration, prepends a second snippet and adds an empty line to the map's mappings. The uploaded copy and its map agree with each other, but the deployed file doesn't have that extra line, so Sentry resolves every frame one line too high.

This is the same mechanism as #2189, with a different trigger: #2190 taught the check Turbopack's _debugIds form, but it still requires quotes.

Reproduction

dir=$(mktemp -d)
cat > "$dir/chunk.js" <<'EOF'
const a=1;
(()=>{try{let e=globalThis,t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`4f39e3c4-c308-4c2e-8975-3241d12fbeef`,e._sentryDebugIdIdentifier=`sentry-dbid-4f39e3c4-c308-4c2e-8975-3241d12fbeef`)}catch{}})();console.log(a);
//# sourceMappingURL=chunk.js.map
//# debugId=4f39e3c4-c308-4c2e-8975-3241d12fbeef
EOF
echo '{"version":3,"sources":["a.ts"],"names":[],"mappings":"AAAA;AACA","debugId":"4f39e3c4-c308-4c2e-8975-3241d12fbeef"}' > "$dir/chunk.js.map"
npx sentry@0.49.0 sourcemap inject --dry-run --json "$dir"

Expected: "modified": 0, "skipped": 1, as with the same file using " quotes.
Actual: "modified": 1, "skipped": 0.

Suggested fix

Accept a backtick in the quote class:

-  ...\\s*=\\s*(["'])(${DEBUGID_PATTERN})\\1`,
+  ...\\s*=\\s*(["'\`])(${DEBUGID_PATTERN})\\1`,

The backreference still requires matching delimiters. The bracketed key form (\\[\\s*["']${DEBUGID_REGISTRY}["']\\s*\\]) probably wants the same, since a minifier can emit e[`_sentryDebugIds`].

We're working around it with a pnpm patch making exactly this change. With it, all of our uploaded chunks match the deployed files except for the appended //# debugId= comment, and their maps are unchanged.

Activity

  1. linear-code commented on Nov 13, 2026

    @linear-code
  2. sentry-junior commented on Nov 26, 2026

    @sentry-junior
    Contributor

    This looks like a duplicate of #2267, which #2268 fixed on main (aa80347). That change makes the registration check accept backticks around the ID and around the bracketed registry name (e[`_sentryDebugIds`]), which is the fix suggested here, plus Oxc's ||= / ??= Turbopack form. It first shipped in cli@0.50.0.

    Checked on current main (2f5996c):

    • The reproduction in this issue, run from source with sourcemap inject --dry-run --json, gives "modified": 0, "skipped": 1.
    • A real chunk built with rolldown 1.2.14 (minify: true, Oxc) and @sentry/bundler-plugins 11.12.0's rollup plugin, with the //# debugId= comment appended the way the plugin stages its upload copy: the JS is left byte-identical and mappings is unchanged. The pre-fix(cli): Recognize debug ID snippets from Oxc and React Native Metro #2268 regex finds no registration in that file.
    • The templateLiterals and bracketTemplateRegistry cases in packages/cli/test/lib/sourcemap/inject.test.ts cover this form for external and inline maps.

    There's one related case this issue doesn't cover: a staged chunk that has the snippet but neither a //# debugId= comment nor a map ID. That's #2269, and #2270 handles it.

    If you're on sentry ≥ 0.50.0, you can drop the pnpm patch. Unless you still see the shift on 0.50.0+, I think this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions