Skip to content

fix: handle excluded shared keys and scoped remote names in dev bootstrap#669

Merged
gioboa merged 3 commits intomodule-federation:mainfrom
Staremang:fix/manifest-and-entry
Apr 29, 2026
Merged

fix: handle excluded shared keys and scoped remote names in dev bootstrap#669
gioboa merged 3 commits intomodule-federation:mainfrom
Staremang:fix/manifest-and-entry

Conversation

@Staremang
Copy link
Copy Markdown
Contributor

Bug 1: generateMFManifest crashes on shared keys removed by excludeSharedSubDependencies

The new excludeSharedSubDependencies (dev mode only) deletes a shared key from options.shared if it is a dependency of another shared package. But the key may already be in usedShares (added earlier by createEarlyVirtualModulesPlugin, enforce: "pre"). When /mf-manifest.json is requested, generateMFManifest iterates usedShares, calls getNormalizeShareItem(key) (returns undefined), then crashes on shareItem.version. Dev server responds 500 and the host fails with RUNTIME-003: Failed to get manifest.

generateLocalSharedImportMap in the same file already guards against this — generateMFManifest was missing the same check.

Repro: share two packages where one is listed as a dependency of the other (e.g. @scope/components deps include @scope/utils, both shared).

Fix in src/plugins/pluginMFManifest.ts: switch .map() to .flatMap() and skip entries with no shareItem.

Bug 2: Scoped remote names break the auto-preload bootstrap

pluginAddEntry.ts builds the host bootstrap with:

.filter((remote) => remote.includes('/'))

intending to keep only sub-path entries (e.g. remote/App) and skip bare container names (remote). For scoped remotes like @scope/remote, the / from the scope makes the bare name pass the filter. The generated bootstrap then calls runtime.loadRemote("@scope/remote") with no exposed path, which is translated into module . and fails with Module . does not exist in container. The host never boots.

Repro: any host with a scoped remote (@scope/remote) where the remote only declares sub-path exposes (no '.').

Fix in src/plugins/pluginAddEntry.ts: compare against the remote key instead of using the / heuristic.

const remotePreloads = Object.entries(getUsedRemotesMap())
  .flatMap(([remoteKey, remotes]) =>
    Array.from(remotes).filter((remote) => remote !== remoteKey)
  )
  .sort()
  .map((remote) => `runtime.loadRemote(${JSON.stringify(remote)})`)
  .join(',');

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 29, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@module-federation/vite@669

commit: a3ead43

@Staremang Staremang changed the title Fix: handle excluded shared keys and scoped remote names in dev bootstrap fix: handle excluded shared keys and scoped remote names in dev bootstrap Apr 29, 2026
Copy link
Copy Markdown
Collaborator

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests With Different Frameworks

Image

@gioboa gioboa merged commit 6656f43 into module-federation:main Apr 29, 2026
19 checks passed
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.

2 participants