fix(vite): evaluate transitively bundled deps on first use - #11465
Merged
Merged
Conversation
|
View your CI Pipeline Execution ↗ for commit a82b6e9
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
triniwiz
force-pushed
the
fix/vite-deps-bundle-lazy-transitive
branch
from
September 28, 2026 04:56
562c31f to
e292221
Compare
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.
PR Checklist
What is the current behavior?
The dev deps bundle registers every
node_modulesfile it discovers through a staticimport *, including files it only reached transitively. All of them are therefore evaluated when the bundle loads. Some of those modules are only everrequire()d inside atry/catchby the code that uses them, and throw by design on a platform they don't support. Evaluated eagerly, the throw escapes that guard and aborts the whole dev session.What is the new behavior?
Files that are only reached transitively are registered behind a getter that evaluates them on first read, as the dependency graph would. The first read replaces the getter with the namespace. CommonJS files get the same namespace shape esbuild's
import *gives (named exports, the module asdefaultunless it's__esModule). Entry files are still imported eagerly.Tests:
packages/vite/hmr/server/deps-bundle.spec.tshas an end-to-end esbuild case where a package guards arequireof a dependency whose file throws on evaluation. Loading the bundle doesn't throw, the guarded require still catches it, and reading the key directly still throws. There are also entry-code cases for ESM and CommonJS lazy files. All 51 tests in the file pass.