Skip to content

fix: include importer in SSR externalization cache key#22080

Open
deyaaeldeen wants to merge 1 commit intovitejs:mainfrom
deyaaeldeen:fix/external-cache-importer-aware
Open

fix: include importer in SSR externalization cache key#22080
deyaaeldeen wants to merge 1 commit intovitejs:mainfrom
deyaaeldeen:fix/external-cache-importer-aware

Conversation

@deyaaeldeen
Copy link
Copy Markdown

Problem

createIsExternal caches externalization decisions in a processedIds map keyed solely by the bare specifier string, ignoring the importer. In monorepos where different importers resolve the same bare specifier to different physical packages (e.g., @azure/core-lro@2.7.2 vs @azure/core-lro@3.x in a pnpm workspace), the first resolution's externalization decision is incorrectly served to all subsequent importers.

Fix

Use a composite cache key ${id}\0${importer} so each (specifier, importer) pair is evaluated independently. Builtins and same-importer lookups still benefit from the cache. The performance impact is negligible since tryNodeResolve inside isConfiguredAsExternal already uses packageCache.

Context

Discovered via vitest#10028 in the azure-sdk-for-js monorepo, where the cache causes @azure/core-lro@2.7.2's externalization result to be applied to @azure/core-lro@3.x, leading to unresolved bare specifiers reaching the module runner and a runtime crash:

SyntaxError: The requested module '@azure/core-lro' does not provide an export named 'deserializeState'

Fixes #22078

The `processedIds` cache in `createIsExternal` keys entries by bare
specifier alone, ignoring the importer. In monorepos where different
importers resolve the same specifier to different physical packages
(e.g., `@azure/core-lro@2.7.2` vs `@azure/core-lro@3.x`), the first
resolution's externalization decision is incorrectly reused for all
subsequent importers.

Fix: use a composite cache key of `${id}\0${importer}` so each
(specifier, importer) pair is evaluated independently.

Fixes vitejs#22078

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@deyaaeldeen deyaaeldeen force-pushed the fix/external-cache-importer-aware branch from 84495f2 to e8d28ff Compare March 31, 2026 01:38
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.

SSR externalization cache (processedIds) ignores importer, serves wrong decision for duplicate dependencies

1 participant