Skip to content

fix(vite): fold an exports-map plugin's root entry onto its bare package id - #11411

Merged
NathanWalker merged 1 commit into
mainfrom
fix/vite-plugin-exports-root-entry
Sep 3, 2026
Merged

NathanWalker merged 1 commit into
mainfrom
fix/vite-plugin-exports-root-entry

Conversation

@NathanWalker

Copy link
Copy Markdown
Contributor

resolveInternalRuntimePluginBareSpecifier decides which vendor id a NativeScript plugin import is served under on device. Vite resolves import { x } from '@scope/plugin' through the package's exports map to the concrete file (/node_modules/@scope/plugin/dist/index.js) before the rewriter sees it. For a plugin with an exports map the function then keeps that concrete subpath as the vendor id:

if (originalSpec && originalSpec !== packageName) return null;      // subpath export
if (!packageMainInfo.hasExports && subpathMatchesMainEntry(...)) return packageName;  // main-field packages only
return normalized;                                                    // -> '@scope/plugin/dist/index.js'

The device vendor registry is keyed on bare package ids, so __nsVendorRequire('@scope/plugin/dist/index.js') misses the deps bundle, falls to the runtime's base require and comes back as an empty placeholder module. Every named import is undefined and the app dies at the first call (registerElement is not a function). This is the same failure the subpathMatchesMainEntry comment describes for extensionless main fields, reached through the other package shape.

Fix

Consult the exports reverse map first: when the resolved file is what the package's root export points to, return the bare package id. Subpath exports still return null (left to the vendor resolver), package-internal files still keep their concrete specifier, and main-field packages resolved to a platform file (dist/index.ios.js) still fold through subpathMatchesMainEntry.

…age id

Vite resolves a bare plugin import through the package's `exports` map to
the concrete file before the rewriter sees it. For a NativeScript plugin
with an `exports` map, `resolveInternalRuntimePluginBareSpecifier` kept
that concrete subpath (`@scope/plugin/dist/index.js`) as the vendor id,
which the device vendor registry (keyed on bare package ids) cannot serve;
the import fell to the runtime's base require and came back as an empty
placeholder module, so every named import was undefined.

Consult the exports reverse map first and return the bare package id when
the resolved file is the root export. Subpath exports still return null,
package-internal files keep their concrete specifier, and main-field
packages resolved to a platform file still fold through
subpathMatchesMainEntry.
@nx-cloud

nx-cloud Bot commented Sep 2, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit c8108ec

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 49s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

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


☁️ Nx Cloud last updated this comment at 2026-09-02 22:52:12 UTC

@pkg-pr-new

pkg-pr-new Bot commented Sep 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: c8108ec

@NathanWalker
NathanWalker merged commit a76525a into main Sep 3, 2026
10 checks passed
@NathanWalker
NathanWalker deleted the fix/vite-plugin-exports-root-entry branch September 3, 2026 17:21
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.

1 participant