Skip to content

fix(vite): evaluate transitively bundled deps on first use - #11465

Merged
NathanWalker merged 2 commits into
mainfrom
fix/vite-deps-bundle-lazy-transitive
Sep 29, 2026
Merged

NathanWalker merged 2 commits into
mainfrom
fix/vite-deps-bundle-lazy-transitive

Conversation

@triniwiz

@triniwiz triniwiz commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

PR Checklist

What is the current behavior?

The dev deps bundle registers every node_modules file it discovers through a static import *, including files it only reached transitively. All of them are therefore evaluated when the bundle loads. Some of those modules are only ever require()d inside a try/catch by 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 as default unless it's __esModule). Entry files are still imported eagerly.

Tests: packages/vite/hmr/server/deps-bundle.spec.ts has an end-to-end esbuild case where a package guards a require of 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.

@nx-cloud

nx-cloud Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit a82b6e9

Command Status Duration Result
nx run-many -t build -p core,webpack5,vite ✅ Succeeded 7s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-09-29 22:01:22 UTC

@pkg-pr-new

pkg-pr-new Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11465
npm i https://pkg.pr.new/@nativescript/vite@11465
npm i https://pkg.pr.new/@nativescript/webpack@11465

commit: a82b6e9

@triniwiz
triniwiz force-pushed the fix/vite-deps-bundle-lazy-transitive branch from 562c31f to e292221 Compare September 28, 2026 04:56
@triniwiz
triniwiz changed the base branch from feat/windows to main September 28, 2026 04:56
@NathanWalker
NathanWalker merged commit ef297bc into main Sep 29, 2026
10 checks passed
@NathanWalker
NathanWalker deleted the fix/vite-deps-bundle-lazy-transitive branch September 29, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants