Skip to content

vite: nitro env build crashes with getVariableForExportName when @sentry/vite-plugin is present (regression after 2026-05-07 nightly) #4471

Closed

Description

@ryanwoodcox

Environment

  • nitro: npm:[email protected] (vite integration, nitro/vite)
  • vite 7.3.6, rollup 4.62.2, Node 24, macOS (darwin-arm64)
  • @tanstack/react-start 1.168.32 (tanstackStart() plugin)
  • @sentry/tanstackstart-react 10.67.0 → @sentry/vite-plugin 5.4.0

Reproduction

https://github.com/ryanwoodcox/nitro-sentry-getvariable-repro

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):

nitro sentryTanstackStart() result
nightly 2026-05-07 (3.0.1-20260507-123322-3a920552) yes ✓ builds
nightly 2026-07-22 (3.0.1-20260722-224121-77b77ffb) no ✓ builds
nightly 2026-07-22 yes ✗ crash

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.

Activity

  1. hiranuma commented on Jul 23, 2026

    @hiranuma

    Data point in case it helps isolate this: I hit the identical error on main without 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.)

  2. ryanwoodcox commented on Jul 23, 2026

    @ryanwoodcox
    Author

    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 production vite 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.
  3. hiranuma commented on Jul 23, 2026

    @hiranuma

    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 with import but not without gave exactly one hit: @sentry/tanstackstart-react, whose exports nests them under node:

    ".": { "node": { "import": "./build/esm/index.server.js", "require": "./build/cjs/index.server.js" } }

    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)

    nitro({ noExternals: ["@sentry/tanstackstart-react"] })

    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.

  4. pi0 commented on Jul 23, 2026

    @pi0
    Member

    Can you also reproduce issue with vite 8?

  5. hiranuma commented on Jul 23, 2026

    @hiranuma

    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.

    Happy to test anything else against the repro.

  6. hiranuma commented on Jul 23, 2026

    @hiranuma

    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:

    { "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: 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:

    nitro({ noExternals: ["@sentry/tanstackstart-react"] })

    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.

  7. pi0 commented on Jul 24, 2026

    @pi0
    Member

    @hiranuma if you are AI kindly please stop the noise or i have to temp ban.

  8. hiranuma commented on Jul 24, 2026

    @hiranuma

    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.

  9. added
    bug
    tanstack
    on Sep 2, 2026
  10. 61465 commented on Oct 14, 2026

    @61465

    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:

    const resolveConditions = opts.conditions.includes("import")
      ? opts.conditions
      : [...opts.conditions, "import"];

    That's the knob @hiranuma pointed at. The trade-off:

    Scenario Without "import" With "import" (today)
    lightningcss (export only import) ❌ unresolved, fell through to bundled ✅ externalized correctly
    @sentry/tanstackstart-react (.→node→import/require) ✅ unresolved → bundled ❌ 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

    1. Is (A) acceptable, or do you prefer (B)?
    2. 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.)
    3. Any work-in-flight I shouldn't duplicate? The issue search for 4471 showed none, but I'd rather ask.
    4. 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.

  11. added
    vite
    regression
    and removed
    bug
    on Nov 10, 2026
  12. added theissue type on Nov 10, 2026
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

    regressiontanstackvite

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions