Repository navigation
fix(vite): keep source-only dependencies out of the HMR vendor bundle regardless of spec - #11560
Merged
NathanWalker merged 3 commits intoOct 21, 2026
Conversation
… regardless of spec
isUnvendorableLocalSource only ran its compiled-JS check for file:
directory specs, so semver/git/url deps — and semver specs whose install
linked a source checkout (e.g. a pnpm readPackage hook) — were swept into
the standalone esbuild vendor bundle even when the installed package ships
only TypeScript/TSX source. That pipeline has none of the app's Vite
plugins (tsconfig-paths resolver, JSX transforms, custom loaders like
.tsrx), so vendoring such a package fails the whole bundle or silently
stubs its imports.
- The source check now applies to every non-link:/workspace: spec via a
classifyPackageEntry() classifier ('compiled' | 'source' | 'unknown').
- Manifest lookup falls back to a direct package.json probe over the
require resolution dirs when exports omit ./package.json, so those
packages classify correctly instead of bailing out.
- Extensionless mains that name a directory (main: "lib") now also probe
<dir>/index<ext>, matching Node's directory-as-entry behavior.
When the installed package.json can't be found or parsed ('unknown'), the
behavior is unchanged: file: directory specs still skip vendor and every
other spec still vendors.
|
View your CI Pipeline Execution ↗ for commit 395ceb5
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
…g vendor deps A package with no entry file on disk (stale `main`, subpath-only layout, wildcard-only `exports`) was classified as source-only and dropped from the vendor bundle for every spec. That unvendored NativeScript plugins whose stale `main` esbuild still resolves through the `index.<platform>.js` fallback, and stopped vendoring the imported subpaths of monorepo root deps without a root entry. Such packages now fall back to the spec-based decision, as before.
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?
isUnvendorableLocalSourcekeeps a dependency out of the vendor bundle only in two cases:link:orworkspace:;file:directory and the package has no compiled JS entry.Every other spec is vendored, even when the installed package ships only TypeScript source. That includes semver, git, url and
file:tarballs. Examples of affected packages:.ts("exports": { ".": "./src/index.ts" });readPackagehook replaced with a symlink to a source checkout.The vendor bundle is built by esbuild without the app's Vite plugins, so source packages break in it:
No loader is configured for ".tsrx" files.What is the new behavior?
link:/workspace:, which are still always skipped. A package with a compiled.js/.mjs/.cjsentry is vendored. A package without one is served through the Vite pipeline, the same wayfile:source directories already are.package.jsoncan't be found or read, the result is the same as before.file:directories are skipped; every other spec is vendored.exportsdoesn't include./package.jsonwere treated as having no compiled entry. The check now falls back to looking for<dir>/<name>/package.jsoninrequire.resolve.paths(name).main: "lib"now also checkslib/index.js(and the platform variants), the way Node resolves a directory.Reproduction
The fixture app depends on
"src-lib": "1.0.0", which exports./src/index.ts. That file imports~lib/x(a tsconfig path alias) and./ui.tsrx(handled by an app Vite plugin). The repro runscollectVendorModulesfollowed by the vendor esbuild build (vendorManifestPlugin.buildStart) on Vite 8.3.4.src-libvendored@nativescript/vite@8.0.19No loader is configured for ".tsrx" files(~lib/xwas also replaced by a stub that throws)Tests
manifest.spec.tshas a newcollectVendorModules — source-only dependenciessuite. It checks that these are excluded:It also checks that these are still vendored:
exportsdoesn't include./package.json;mainthat points at a directory;index.ios.js/index.android.js;file:tarball;file:directories, both compiled and source;The two exclusion tests fail on
main.npx vitest runinpackages/vite: 1845 passed, 1 skipped.Notes
package.jsonresolves but which has no JS entry at all is now served through Vite instead of being vendored. Three existingcollectVendorModulesfixtures were like this (only apackage.json). I added a stubindex.jsto each so they still test the flavor and policy exclusions they were written for..entry) are handled.