Repository navigation
fix(build): do not assign rollup lib chunks to plugin-only loaded modules - #5104
Merged
Merged
Conversation
…ules Modules loaded via `this.load()` (e.g. commonjs probing an import that `nitro:externals` then externalizes) stay in Rollup's graph unlinked; assigning them to a `_libs` chunk crashed rendering (#4471).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
commit: |
pi0
marked this pull request as ready for review
November 10, 2026 18:55
pi0
approved these changes
Nov 10, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #4471
With Rollup (rollup builder, or Vite 7),
nitro:externalscallsthis.resolve(), and the commonjs plugin'sresolveIdthenthis.load()s the target to check if it is CJS. When nitro externalizes that import, the loaded module stays in Rollup's graph with no importers and never gets its imports linked.Rollup calls
manualChunksfor every module in the graph, so our_libs/<pkg>assignment put these orphans in a chunk, and rendering one that has both a direct export and a re-export crashed withCannot read properties of null (reading 'getVariableForExportName'). #4471 hits this with@sentry/tanstackstart-react, which is externalized since d7a3447 added theimportcondition.The fix: a shared
libManualChunks(rollup builder and the Vite 7 path) skips modules that are not entries and have no importers, dynamic importers orimplicitlyLoadedAfterOneOf. Orphans are never included in output, so no code is dropped. The only output change is that an empty, unimported_libs/<pkg>.mjsthat such apps used to get is no longer emitted.Testing:
test/unit/chunks.test.tsreproduces the crash with plain Rollup (fails without the fix)..output/server/node_modules/@sentry, same as on Vite 8.NITRO_BUILDER=rolluptest suite passes.Notes:
@sentry/tanstackstart-reactnow end up externalized and traced on Vite 7 (previously a crash; before d7a3447 they were bundled). This matches what Vite 8 already produces. Sentry instrumentation at runtime was not verified, since the repro never callsSentry.init.assignManualChunkspassing modules that are never included) could be reported to Rollup separately.rollupConfig.output.manualChunksoverrides ours in the rollup builder, so such configs are not covered. On the Vite 7 path ours still takes precedence, as before.🤖 Generated with AI assistant