Skip to content

@sentry/nextjs 11: orchestrion banner is prepended after the source map is written, so webpack server stack traces point at the wrong line #27134

Backlog

Description

@pahan35

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

First observed by us on 11.10.0 (also reproduced on 11.11.0). Still reproduces on 11.23.0.

Framework Version

First observed on Next.js 16.4.3, still reproduces on 16.5.0. next build --webpack, Node 24.

Link to Sentry event

No response

Reproduction Example/SDK Setup

Minimal app with default withSentryConfig options, except sourcemaps.delete: false. Since the sourcemaps.upload / delete options landed, the SDK emits .map files only with upload credentials or with delete: false, so the repro needs it to keep the maps on disk. With upload credentials (our real setup) the SDK takes the same branch and sets devtool: 'source-map' for the server build.

package.json

{
  "scripts": { "build": "next build --webpack", "check": "node check.mjs" },
  "dependencies": {
    "@sentry/nextjs": "11.23.0",
    "next": "16.5.0",
    "react": "19.3.1",
    "react-dom": "19.3.1"
  },
  "devDependencies": { "source-map-js": "1.2.1" }
}

next.config.mjs

import { withSentryConfig } from '@sentry/nextjs/config'

export default withSentryConfig(
  {},
  {
    org: 'example-org',
    project: 'example-project',
    silent: true,
    // Keep the .map files (11.2x only emits them with upload credentials or this).
    sourcemaps: { delete: false },
    ...(process.env.REPRO_NO_BTI === '1' && { buildTimeInstrumentation: false }),
  }
)

app/layout.js

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  )
}

app/page.js

export const dynamic = 'force-dynamic'

async function loadThing(id) {
  if (!id) {
    throw new Error('repro marker: thrown on line 5')
  }
  return { id }
}

export default async function Page({ searchParams }) {
  const { id } = await searchParams
  const thing = await loadThing(id)
  return <p>{thing.id}</p>
}

check.mjs (looks up the throw in the built server entry's own source map)

import fs from 'node:fs'
import { SourceMapConsumer } from 'source-map-js'

const file = '.next/server/app/page.js'
const code = fs.readFileSync(file, 'utf8')
const map = JSON.parse(fs.readFileSync(`${file}.map`, 'utf8'))
const consumer = new SourceMapConsumer(map)

const line1 = code.split('\n')[0]
const col = line1.indexOf('Error("repro marker')
if (col < 0) throw new Error(`marker not found on line 1 of ${file}`)

const banner = ';(function(){var g=globalThis.__SENTRY_ORCHESTRION__'
const bannerLen = line1.startsWith(banner) ? line1.indexOf('})();') + 5 : 0

const at = (c) => {
  const p = consumer.originalPositionFor({ line: 1, column: c })
  return `${p.source?.replace(/^.*\/app\//, 'app/')}:${p.line}:${p.column}`
}
console.log('lines in built file:      ', code.split('\n').length)
console.log('orchestrion banner length:', bannerLen)
console.log(`marker at generated 1:${col} ->`, at(col), '(expected app/page.js:5)')
if (bannerLen) console.log('same lookup minus banner   ->', at(col - bannerLen))

Steps to Reproduce

  1. npm install && npm run build && npm run check
  2. Control: rm -rf .next && REPRO_NO_BTI=1 npm run build && npm run check

Expected Result

The throw resolves to app/page.js:5, as it does with buildTimeInstrumentation: false:

lines in built file:       2
orchestrion banner length: 0
marker at generated 1:2474 -> app/page.js:5:10 (expected app/page.js:5)

Actual Result

With the default options the lookup misses the throw. On 11.23.0 + Next 16.5.0 it doesn't even land in app/page.js. Subtracting the banner length gives the right position:

lines in built file:       2
orchestrion banner length: 127
marker at generated 1:2601 -> webpack://sentry-orchestrion-sourcemap-repro/sentry-wrapper-module:13:12 (expected app/page.js:5)
same lookup minus banner   -> app/page.js:5:10

On 11.11.0 + Next 16.4.3 (no sourcemaps.delete needed there) the same repro gave app/page.js:13:9, 8 lines below the throw.

In Sentry this shows up as the wrong source context on server errors. In our app (11.10.0, Next 16.4.3) a throw inside a try/catch on line 37 was shown on line 46, inside an unrelated getCompanyMeetings(...) call. It sent us to look at the wrong code path first.

Additional Context

It looks like a stage-order issue in the vendored @apm-js-collab/code-transformer-bundler-plugins webpack plugin (in @sentry/server-utils: build/cjs/orchestrion/bundler/webpack.js on 11.23.0, build/cjs/vendored/@apm-js-collab/code-transformer-bundler-plugins/dist/esm/webpack.js on 11.10/11.11; upstream src/webpack.ts):

  1. buildTimeInstrumentation (default true) adds the plugin with injectDiagnostics, which returns ORCHESTRION_BUNDLER_MARKER_BANNER (127 chars, no trailing newline).
  2. The plugin prepends it to every entry asset with new ConcatSource(injectCode, source) at PROCESS_ASSETS_STAGE_SUMMARIZE (1000).
  3. webpack's SourceMapDevToolPlugin writes the .map earlier, at PROCESS_ASSETS_STAGE_DEV_TOOLING (500). So the emitted map never includes the banner.
  4. Server chunks are minified onto one line, so every column on that line is off by 127. Unminified chunks only shift line 1, which is why it's easy to miss.

What I checked in our app build (11.10.0, Next 16.4.3):

  • The minifier's output map (dumped at OPTIMIZE_SIZE + 1) maps the throw to the right line.
  • The emitted .map has exactly the same mappings as that minifier output. The emitted .js is the minifier output plus the 127-char banner.
  • experimental.serverMinification: false hides it (line 1 is no longer the whole file).

Possible fix: inject the banner at any stage before DEV_TOOLING, so the devtool plugin sees the ConcatSource and shifts the map. I patched the bundled plugin in the repro:

  • PROCESS_ASSETS_STAGE_DEV_TOOLING - 1: banner stays verbatim (127 chars), throw → app/page.js:5:14. Checked on 11.11.0 and 11.23.0.
  • PROCESS_ASSETS_STAGE_ADDITIONS: also correct, but the banner then goes through the minifier. Checked on 11.11.0 only.

src/webpack.ts on upstream main still uses SUMMARIZE.

Workaround for now: buildTimeInstrumentation: false, at the cost of the build-time instrumentation.

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Activity

  1. linear-code commented on Dec 3, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Dec 3, 2026
  3. andreiborza commented on Dec 4, 2026

    @andreiborza
    Member

    Hi @pahan35, thanks for writing in. There's a PR to fix this (apm-js-collab/code-transformer-bundler-plugins#55), so we are waiting on that.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Dec 4, 2026
  5. pahan35 commented on Dec 4, 2026

    @pahan35
    Author

    Hi @andreiborza,

    Thanks for your answer here sharing the details!

    We'll pay attention to that PR to understand when to expect the issue to be fixed.

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Dec 4, 2026
  7. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Dec 4, 2026
  8. timfish commented on Dec 5, 2026

    @timfish
    Collaborator

    @apm-js-collab/code-transformer-bundler-plugins v0.7.7 has been released so if you update your dependencies you should get this version.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions