Skip to content

fix(vite): shim package roots whose export * targets another bundled package - #11426

Closed
sitefinitysteve wants to merge 1 commit into
NativeScript:mainfrom
sitefinitysteve:fix/vite-deps-shim-bare-star
Closed

sitefinitysteve wants to merge 1 commit into
NativeScript:mainfrom
sitefinitysteve:fix/vite-deps-shim-bare-star

Conversation

@sitefinitysteve

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

The Vue server strategy pins bare nativescript-vue in the device import map to /ns/m/node_modules/nativescript-vue, expecting that URL to serve the deps-bundle shim. It doesn't: collectDepsModuleExportInfo returns names: null for the package root because nativescript-vue/dist/index.js contains a bare export * from '@vue/runtime-core', and getShimForSpec only emits a shim when the export surface is enumerable. The real file is served per-module instead, so any node_modules file served per-module that imports nativescript-vue bare (for example @nativescript-community/ui-collectionview/vue3) evaluates the root a second time, and its module-scope init() re-registers the core elements:

Error: Element for AbsoluteLayout already registered.

Repro, controls and the NS_VENDOR_INCLUDE workaround are in #11421.

What is the new behavior?

generateDepsBundle now records, from esbuild's discovery metafile, how the bundle actually resolved every bare import edge: importer key → bare specifier → target key (bareImportEdges, persisted in the disk cache; schema bumped so existing caches rebuild). collectDepsModuleExportInfo takes an optional resolver for bare export * targets, and the bundle service backs it with those recorded edges, so the shim enumerates exactly the file esbuild bundled for that importer — no filesystem guessing, no condition lists. If there is no recorded edge, or no resolver, the collector bails to names: null as before and per-module serving is unchanged. With this, nativescript-vue's root gets a real shim and the bare specifier lands in the single bundle realm the strategy already assumes.

Specs: an end-to-end createDepsBundleService case with a fixture root that does export * from 'pkg-i' asserts the served shim re-exports both its own and the target's names through real esbuild; the recorded edges are asserted and round-tripped through the disk cache; collector unit cases cover resolver hit, no edge, and an opaque-CJS target (bails).

Residual risks worth knowing, none new to this change: registry keys collapse nested and hoisted copies of a package to one identity (pre-existing model for every shim); an ambiguous name across two export * targets is unioned and reads as undefined if absent from the bundled namespace, the same behaviour relative stars already have; and the guard that skips namespaced (:) metafile targets has no dedicated spec.

Verified on device with the #11421 repro (blank Vue app importing @nativescript-community/ui-collectionview/vue3, no NS_VENDOR_INCLUDE): the published 8.0.5 crashes with the error above; this build boots cold and from the rebuilt disk cache, the served nativescript-vue URL is the bundle shim, and live edits hot-reload.

Fixes #11421.

@nx-cloud

nx-cloud Bot commented Sep 10, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit c21a9f2

Command Status Duration Result
nx run-many --target=test --configuration=ci --... ✅ Succeeded 2s View ↗

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


☁️ Nx Cloud last updated this comment at 2026-09-10 00:00:26 UTC

@nx-cloud

nx-cloud Bot commented Sep 10, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit c21a9f2

Command Status Duration Result
nx run-many --target=test --configuration=ci --... ✅ Succeeded 5s View ↗

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


☁️ Nx Cloud last updated this comment at 2026-09-10 00:00:41 UTC

@pkg-pr-new

pkg-pr-new Bot commented Sep 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: c21a9f2

@sitefinitysteve

Copy link
Copy Markdown
Contributor Author

@NathanWalker Looks like we crossed lol NativeScript/NativeScript#11427 happy to close this in favour of it.

One thought from this branch in case it's useful... instead of re-resolving the bare target from the importer, I recorded the original -> path edges esbuild already emits in the discovery metafile (import-statement kind only) and followed those, so the shim's names are guaranteed to be the file esbuild bundled even when a scanner and esbuild disagree on an exports condition. Also has a real-esbuild spec for a require-first conditional-exports package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant