fix(vite): fold an exports-map plugin's root entry onto its bare package id - #11411
Merged
Merged
Conversation
…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.
|
View your CI Pipeline Execution ↗ for commit c8108ec
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
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.
resolveInternalRuntimePluginBareSpecifierdecides which vendor id a NativeScript plugin import is served under on device. Vite resolvesimport { x } from '@scope/plugin'through the package'sexportsmap to the concrete file (/node_modules/@scope/plugin/dist/index.js) before the rewriter sees it. For a plugin with anexportsmap the function then keeps that concrete subpath as the vendor id: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 isundefinedand the app dies at the first call (registerElement is not a function). This is the same failure thesubpathMatchesMainEntrycomment describes for extensionlessmainfields, 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, andmain-field packages resolved to a platform file (dist/index.ios.js) still fold throughsubpathMatchesMainEntry.