You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vite: nitro env build crashes with getVariableForExportName when @sentry/vite-plugin is present (regression after 2026-05-07 nightly) #4471
npm install && npm run build — the client and ssr environments build fine; the nitro environment crashes during Bundle.generate.
Describe the bug
Production builds crash in the nitro env whenever the Sentry vite plugin (sentryTanstackStart(), i.e. @sentry/vite-plugin) is in the plugin list, on every nightly newer than 2026-05-07:
✗ Build failed
Cannot read properties of null (reading 'getVariableForExportName')
at getVariableForExportNameRecursive (rollup/dist/es/shared/node-entry.js:17211:19)
at Module.getVariableForExportName
at Module.getExportedVariablesByName
at Module.getRenderedExports
at Chunk.renderModules
at Chunk.render
at renderChunks
at Bundle.generate
at buildEnvironment (vite/dist/node/chunks/config.js)
at buildEnvironments (nitro-nightly/dist/vite.mjs:123:17)
Isolation matrix (all vite 7.3.6 + react-start 1.168.32):
build.sourcemap on/off makes no difference. Bisected from a real app: nightlies 2026-05-19, 2026-06-10, 2026-07-07 (beta), 2026-07-22 all crash; 2026-05-07 is the last good nightly, so the regression landed in the 05-08 → 05-19 window.
Possibly related: in #4436 it was noted that flipping inlineDynamicImports: false on v3/main breaks the rollup build with this exact error — this report may be the same underlying issue reachable via a plugin that injects/references modules across chunks (the Sentry plugin emits debug-ID/release-injection modules into every chunk).
We are currently pinned to the 2026-05-07 nightly as a workaround.
Data point in case it helps isolate this: I hit the identical error on mainwithout any plugins involved.
Setting inlineDynamicImports: false in src/presets/_nitro/nitro-dev.ts and building the dev bundle with NITRO_BUILDER=rollup crashes deterministically with the same Cannot read properties of null (reading 'getVariableForExportName'). With NITRO_BUILDER=rolldown the same change builds fine.
So the trigger doesn't seem to require the Sentry plugin specifically — it looks like plain Rollup code-splitting in the nitro env, and it's rollup-only (rolldown is unaffected). That might make for a smaller repro than a full TanStack Start + Sentry app.
(Context: that experiment came from #4436 / #4435, where the same flag flip is being proposed for the dev preset.)
Thanks — consistent with what we see: with the Sentry plugin removed, our full app builds fine on the same nightly, so in the vite-integration path the plugin is what introduces whatever the rollup-only rendering path trips on.
Two extra data points from testing your rolldown finding:
NITRO_BUILDER=rolldown had no effect on the productionvite build for us — the nitro env still built with rollup and crashed identically (nightly 2026-07-22), so that escape hatch doesn't appear reachable from the vite integration's production path.
Rollup version doesn't matter within the range we've tried: identical crash on rollup 4.59.0 and 4.62.2.
Correction to my earlier comment: my plugin-free inlineDynamicImports: false crash is not a smaller repro for this — it also crashes on the last-good commit 3a920552, so it's a separate, pre-existing rollup + code-splitting problem. Sorry for the noise.
I bisected this one against your repro instead. nitro-nightly versions embed the commit sha, so I installed exact nightlies and ran npm run build:
nitro nightly
Sentry plugin
result
3.0.1-20260507-123322-3a920552
yes
✅ builds
3.0.1-20260507-141654-d7a34477
yes
❌ crash ← first bad
3.0.1-20260519-134624-5b7e152b
yes
❌ crash
3.0.1-20260519-134624-5b7e152b
no
✅ builds
(20260508-97568a04 and 20260511-e770268d crash too.) So both the bad nitro commit and the plugin are needed — matching what you saw.
Only two commits sit between the last-good and first-bad nightly, and one (cf5e8781 — types/cloudflare/firebase/openapi) can't touch the module graph. That leaves d7a34477 — "fix(build): externalize packages with import-only exports" (src/build/plugins/externals.ts). Verified: on current main, reverting only that change (resolveConditions → opts.conditions at its two use sites) makes your repro build.
Why it breaks
d7a34477 appends "import" to the externals resolve conditions (to fix lightningcss). Instrumenting tryResolve to log ids that resolve withimport but not without gave exactly one hit: @sentry/tanstackstart-react, whose exports nests them under node:
With nitro's conditions (production, wasm, unwasm, node) and no implicit import from exsolve, this previously failed to resolve and fell through to being bundled; now it resolves and is externalized, leaving the Rollup graph while the Sentry plugin still references it across chunks — so getVariableForExportNameRecursive hits null. That's also why it's rollup-only, and why dropping the plugin (which is what pulls that package in) makes it build.
Workaround (verified on current main, no nightly pin needed)
A straight revert would regress the lightningcss case, so I'm flagging the trade-off rather than proposing a patch — happy to test any candidate fix against the repro.
No — it does not reproduce on vite 8. Same repro, same nightly (3.0.1-20260722-224121-77b77ffb), Sentry plugin in place:
vite
result
7.3.6 (rollup 4.62.2)
❌ crash
8.1.5 (rollup not installed; ships rolldown 1.2.0)
✅ builds
Two checks so this isn't a false negative:
The Sentry plugin isn't silently inert on vite 8. Beyond the same [sentry-vite-plugin] log output, its debug-ID injection is actually present in the built output — _sentryDebugIds / _sentryDebugIdIdentifier / SENTRY_RELEASE appear across several server chunks (125 occurrences on vite 8, 192 on a passing vite 7 build).
The trigger condition is unchanged.@sentry/tanstackstart-react is still externalized under vite 8 — the built output has a bare from "@sentry/tanstackstart-react" and there's no bundled copy under _libs.
So vite 8 isn't avoiding the externalization introduced by d7a34477, and the plugin is still doing its cross-chunk injection — the same conditions, but rolldown renders that graph fine where rollup hits the null in getVariableForExportNameRecursive.
I spent some time digging into why rollup ends up dereferencing null here, by instrumenting rollup 4.62.2 in the repro. I think it comes down to nitro/vite handing rollup an inconsistent module graph. I should also correct something I guessed earlier: it isn't the plugin's cross-chunk references that go null, but the externalized package's own internal reexport descriptors, which never get linked.
A bit of detail, in case it's useful. Rollup initialises every reexport descriptor as { module: null /* filled in later */ }, and that field is only ever populated by linkImports(). So a null there doesn't mean a lookup missed (that would be undefined); it means linkImports() never ran on that module. And indeed, for @sentry/tanstackstart-react/build/esm/server/index.js, linkImports() runs 0 times, yet it's still reached during rendering:
Chunk.renderModules → getRenderedExports → getVariableForExportName
→ the `export { x } from '…'` branch
→ getVariableForExportNameRecursive(reexportDeclaration.module = null, …)
→ null.getVariableForExportName(…) // crash
The reason it's never linked is the inconsistency. At the crash, the descriptor's resolvedId is:
So vite had resolved the package's internal files as non-external and set up reexport descriptors between them, while the externals plugin externalizes the package. Rollup therefore never loads those internal files, and the descriptors point at modules that were never added to the graph. That lines up with the bisect: d7a34477 is what flips this package from bundled to externalized. It isn't limited to that one file either; with the null-deref skipped, the same thing surfaces across the externalized sentry/opentelemetry subtree.
I don't want to guess where the right fix belongs, so just two observations:
On the nitro side, the graph could be made consistent. As a stopgap, this builds cleanly on the current nightly:
I'd treat that as an unblock rather than a fix, though: it bundles the SDK, and since @sentry/node leans on OpenTelemetry's load-time instrumentation, I'd want to confirm that still works at runtime (I only checked the build). Reverting d7a34477 also builds, but it brings back what that commit fixed: packages with import-only exports like lightningcss stop resolving under nitro's conditions and get bundled instead of externalized (I confirmed that with exsolve), so that doesn't seem right either.
On the rollup side, and separately, it might be worth guarding this. The same branch reports a missing variable via logMissingExport, but a missing module isn't checked, so it just derefs null with no hint as to which module/export, which is what made this hard to trace. I'm happy to file that upstream with a minimal repro if you think it's warranted.
Either way I'm glad to test any candidate fix against the repro, just let me know.
I am not AI. I spent my own time on the extra investigation because I just wanted to contribute to solving this issue, but I won't post anymore on this. Sorry for the noise.
Picking this up — proposing a conditions-aware fix that keeps the lightningcss case
Thanks @hiranuma for the surgical bisect — it saves everyone a lot of time. CONTRIBUTING asks for a discussion before a PR, so I'd rather confirm direction here first than open one cold.
Scope confirmed on current main.src/build/plugins/externals.ts:52-54 still unconditionally appends "import" to the externals resolve conditions:
❌ externalized → Rollup getVariableForExportName crash via Sentry plugin
A straight revert flips the two columns, so neither direction is a win alone. @hiranuma's workaround (noExternals: ["@sentry/tanstackstart-react"]) papers over it per-user.
Two shapes a fix can take
(A) Scope the "import" condition to pass-1 "would-this-even-resolve?" probes, not final externalization.
Run tryResolve twice when the first attempt fails: once with opts.conditions, once with [...opts.conditions, "import"]. If the strict pass resolves, use its result (so @sentry/tanstackstart-react keeps falling through to bundled); only promote to the +import resolution if the strict pass is empty (so lightningcss still externalizes). The cost is one extra resolve per unresolved id, which is negligible outside the dep-graph's cold edges.
(B) Opt-out list driven by package shape.
Keep the current +import conditions globally, but detect "node-nested with both import+require" exports shapes (which indicate dual-ESM/CJS packages that previously fell through) and refuse to externalize them when the rollup builder is active. The cost is a small shape heuristic in tryResolve's fallback branch.
I'd rank (A) higher — it's purely a lookup-order change, no shape-heuristic, no builder-conditional, and the behavioural difference lives exactly where @hiranuma's bisect showed the drift crept in.
Test matrix I'd add
Resolve a package whose exports only declares import (synthetic lightningcss-shape fixture) → externalized ✅
Resolve a package whose exports nests under node→import/require → not externalized (left bundled) ✅
Nitro build on Vite 7 + Rollup with the Sentry plugin against @hiranuma's repro → no getVariableForExportName ✅
Nitro build on Vite 8 + Rolldown unchanged ✅ (control; verifies we didn't regress rolldown's path)
Asking for direction before coding
Is (A) acceptable, or do you prefer (B)?
Is there a Nitro-side convention for "builder-aware externals" I should respect? (e.g. rolldown builds already skip this path per @hiranuma's rolldown data point.)
Any work-in-flight I shouldn't duplicate? The issue search for 4471 showed none, but I'd rather ask.
CONTRIBUTING asks for maintainer discussion first for substantive changes — this definitely qualifies, so happy to wait on your (and @hiranuma's) read before touching the plugin.
If (A) is a go I'll open a draft PR with the test fixtures above + a repro of the Sentry plugin + Rollup chain in the Nitro test suite, so the regression lands with its own guard. Zero scope creep.
cc @hiranuma — if you'd rather drive this yourself based on the bisect you already did, please say so and I'll close out. The research credit is yours.
cc @pi0 — thanks for keeping the thread alive.
🤖 Used Claude Code for the code-trace and comment drafting; the analysis of the two code paths and the test matrix is mine, signed off on content.
Activity
hiranuma commentedon Jul 23, 2026
Data point in case it helps isolate this: I hit the identical error on
mainwithout any plugins involved.Setting
inlineDynamicImports: falseinsrc/presets/_nitro/nitro-dev.tsand building the dev bundle withNITRO_BUILDER=rollupcrashes deterministically with the sameCannot read properties of null (reading 'getVariableForExportName'). WithNITRO_BUILDER=rolldownthe same change builds fine.So the trigger doesn't seem to require the Sentry plugin specifically — it looks like plain Rollup code-splitting in the nitro env, and it's rollup-only (rolldown is unaffected). That might make for a smaller repro than a full TanStack Start + Sentry app.
(Context: that experiment came from #4436 / #4435, where the same flag flip is being proposed for the dev preset.)
ryanwoodcox commentedon Jul 23, 2026
Thanks — consistent with what we see: with the Sentry plugin removed, our full app builds fine on the same nightly, so in the vite-integration path the plugin is what introduces whatever the rollup-only rendering path trips on.
Two extra data points from testing your rolldown finding:
NITRO_BUILDER=rolldownhad no effect on the productionvite buildfor us — the nitro env still built with rollup and crashed identically (nightly2026-07-22), so that escape hatch doesn't appear reachable from the vite integration's production path.hiranuma commentedon Jul 23, 2026
Correction to my earlier comment: my plugin-free
inlineDynamicImports: falsecrash is not a smaller repro for this — it also crashes on the last-good commit3a920552, so it's a separate, pre-existing rollup + code-splitting problem. Sorry for the noise.I bisected this one against your repro instead. nitro-nightly versions embed the commit sha, so I installed exact nightlies and ran
npm run build:3.0.1-20260507-123322-3a9205523.0.1-20260507-141654-d7a344773.0.1-20260519-134624-5b7e152b3.0.1-20260519-134624-5b7e152b(
20260508-97568a04and20260511-e770268dcrash too.) So both the bad nitro commit and the plugin are needed — matching what you saw.Only two commits sit between the last-good and first-bad nightly, and one (
cf5e8781— types/cloudflare/firebase/openapi) can't touch the module graph. That leavesd7a34477— "fix(build): externalize packages with import-only exports" (src/build/plugins/externals.ts). Verified: on currentmain, reverting only that change (resolveConditions→opts.conditionsat its two use sites) makes your repro build.Why it breaks
d7a34477appends"import"to the externals resolve conditions (to fixlightningcss). InstrumentingtryResolveto log ids that resolve withimportbut not without gave exactly one hit:@sentry/tanstackstart-react, whoseexportsnests them undernode:With nitro's conditions (
production, wasm, unwasm, node) and no implicitimportfrom exsolve, this previously failed to resolve and fell through to being bundled; now it resolves and is externalized, leaving the Rollup graph while the Sentry plugin still references it across chunks — sogetVariableForExportNameRecursivehitsnull. That's also why it's rollup-only, and why dropping the plugin (which is what pulls that package in) makes it build.Workaround (verified on current
main, no nightly pin needed)A straight revert would regress the
lightningcsscase, so I'm flagging the trade-off rather than proposing a patch — happy to test any candidate fix against the repro.pi0 commentedon Jul 23, 2026
Can you also reproduce issue with vite 8?
hiranuma commentedon Jul 23, 2026
No — it does not reproduce on vite 8. Same repro, same nightly (
3.0.1-20260722-224121-77b77ffb), Sentry plugin in place:Two checks so this isn't a false negative:
[sentry-vite-plugin]log output, its debug-ID injection is actually present in the built output —_sentryDebugIds/_sentryDebugIdIdentifier/SENTRY_RELEASEappear across several server chunks (125 occurrences on vite 8, 192 on a passing vite 7 build).@sentry/tanstackstart-reactis still externalized under vite 8 — the built output has a barefrom "@sentry/tanstackstart-react"and there's no bundled copy under_libs.So vite 8 isn't avoiding the externalization introduced by
d7a34477, and the plugin is still doing its cross-chunk injection — the same conditions, but rolldown renders that graph fine where rollup hits thenullingetVariableForExportNameRecursive.Happy to test anything else against the repro.
hiranuma commentedon Jul 23, 2026
I spent some time digging into why rollup ends up dereferencing
nullhere, by instrumenting rollup 4.62.2 in the repro. I think it comes down to nitro/vite handing rollup an inconsistent module graph. I should also correct something I guessed earlier: it isn't the plugin's cross-chunk references that gonull, but the externalized package's own internal reexport descriptors, which never get linked.A bit of detail, in case it's useful. Rollup initialises every reexport descriptor as
{ module: null /* filled in later */ }, and that field is only ever populated bylinkImports(). So anullthere doesn't mean a lookup missed (that would beundefined); it meanslinkImports()never ran on that module. And indeed, for@sentry/tanstackstart-react/build/esm/server/index.js,linkImports()runs 0 times, yet it's still reached during rendering:The reason it's never linked is the inconsistency. At the crash, the descriptor's
resolvedIdis:{ "external": false, "id": ".../server/sdk.js", "resolvedBy": "vite:resolve" }So vite had resolved the package's internal files as non-external and set up reexport descriptors between them, while the externals plugin externalizes the package. Rollup therefore never loads those internal files, and the descriptors point at modules that were never added to the graph. That lines up with the bisect:
d7a34477is what flips this package from bundled to externalized. It isn't limited to that one file either; with the null-deref skipped, the same thing surfaces across the externalized sentry/opentelemetry subtree.I don't want to guess where the right fix belongs, so just two observations:
On the nitro side, the graph could be made consistent. As a stopgap, this builds cleanly on the current nightly:
I'd treat that as an unblock rather than a fix, though: it bundles the SDK, and since
@sentry/nodeleans on OpenTelemetry's load-time instrumentation, I'd want to confirm that still works at runtime (I only checked the build). Revertingd7a34477also builds, but it brings back what that commit fixed: packages with import-onlyexportslikelightningcssstop resolving under nitro's conditions and get bundled instead of externalized (I confirmed that with exsolve), so that doesn't seem right either.On the rollup side, and separately, it might be worth guarding this. The same branch reports a missing variable via
logMissingExport, but a missing module isn't checked, so it just derefsnullwith no hint as to which module/export, which is what made this hard to trace. I'm happy to file that upstream with a minimal repro if you think it's warranted.Either way I'm glad to test any candidate fix against the repro, just let me know.
pi0 commentedon Jul 24, 2026
@hiranuma if you are AI kindly please stop the noise or i have to temp ban.
hiranuma commentedon Jul 24, 2026
I am not AI. I spent my own time on the extra investigation because I just wanted to contribute to solving this issue, but I won't post anymore on this. Sorry for the noise.
61465 commentedon Oct 14, 2026
Picking this up — proposing a conditions-aware fix that keeps the lightningcss case
Thanks @hiranuma for the surgical bisect — it saves everyone a lot of time. CONTRIBUTING asks for a discussion before a PR, so I'd rather confirm direction here first than open one cold.
Scope confirmed on current
main.src/build/plugins/externals.ts:52-54still unconditionally appends"import"to the externals resolve conditions:That's the knob @hiranuma pointed at. The trade-off:
"import""import"(today)lightningcss(export onlyimport)@sentry/tanstackstart-react(.→node→import/require)getVariableForExportNamecrash via Sentry pluginA straight revert flips the two columns, so neither direction is a win alone. @hiranuma's workaround (
noExternals: ["@sentry/tanstackstart-react"]) papers over it per-user.Two shapes a fix can take
(A) Scope the
"import"condition to pass-1 "would-this-even-resolve?" probes, not final externalization.Run
tryResolvetwice when the first attempt fails: once withopts.conditions, once with[...opts.conditions, "import"]. If the strict pass resolves, use its result (so@sentry/tanstackstart-reactkeeps falling through to bundled); only promote to the+importresolution if the strict pass is empty (solightningcssstill externalizes). The cost is one extra resolve per unresolved id, which is negligible outside the dep-graph's cold edges.(B) Opt-out list driven by package shape.
Keep the current
+importconditions globally, but detect "node-nested with both import+require"exportsshapes (which indicate dual-ESM/CJS packages that previously fell through) and refuse to externalize them when the rollup builder is active. The cost is a small shape heuristic intryResolve's fallback branch.I'd rank (A) higher — it's purely a lookup-order change, no shape-heuristic, no builder-conditional, and the behavioural difference lives exactly where @hiranuma's bisect showed the drift crept in.
Test matrix I'd add
exportsonly declaresimport(syntheticlightningcss-shape fixture) → externalized ✅exportsnests undernode→import/require→ not externalized (left bundled) ✅getVariableForExportName✅Asking for direction before coding
rolldownbuilds already skip this path per @hiranuma's rolldown data point.)4471showed none, but I'd rather ask.If (A) is a go I'll open a draft PR with the test fixtures above + a repro of the Sentry plugin + Rollup chain in the Nitro test suite, so the regression lands with its own guard. Zero scope creep.
cc @hiranuma — if you'd rather drive this yourself based on the bisect you already did, please say so and I'll close out. The research credit is yours.
cc @pi0 — thanks for keeping the thread alive.
🤖 Used Claude Code for the code-trace and comment drafting; the analysis of the two code paths and the test matrix is mine, signed off on content.
test(deps): Upgrade TanStack Start, Router, and Nitro (#25445)