Repository navigation
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
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
npm install && npm run build && npm run check- 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):
buildTimeInstrumentation(defaulttrue) adds the plugin withinjectDiagnostics, which returnsORCHESTRION_BUNDLER_MARKER_BANNER(127 chars, no trailing newline).- The plugin prepends it to every entry asset with
new ConcatSource(injectCode, source)atPROCESS_ASSETS_STAGE_SUMMARIZE(1000). - webpack's
SourceMapDevToolPluginwrites the.mapearlier, atPROCESS_ASSETS_STAGE_DEV_TOOLING(500). So the emitted map never includes the banner. - 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
.maphas exactly the samemappingsas that minifier output. The emitted.jsis the minifier output plus the 127-char banner. experimental.serverMinification: falsehides 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.
Metadata
Metadata
Assignees
Projects
- StatusShow more project fieldsNo status
Activity
linear-code commentedon Dec 3, 2026
JS-4222
andreiborza commentedon Dec 4, 2026
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.
pahan35 commentedon Dec 4, 2026
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.
timfish commentedon Dec 5, 2026
@apm-js-collab/code-transformer-bundler-pluginsv0.7.7 has been released so if you update your dependencies you should get this version.