Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: prefer installed shared version over requiredVersion (#829)#830

Merged
gioboa merged 2 commits into
module-federation:mainfrom
dmchoi77:fix/shared-required-version-precedence
Jun 16, 2026
Merged

fix: prefer installed shared version over requiredVersion (#829)#830
gioboa merged 2 commits into
module-federation:mainfrom
dmchoi77:fix/shared-required-version-precedence

Conversation

@dmchoi77

Copy link
Copy Markdown
Contributor

Summary

Fixes #829.

This changes shared version normalization so inferVersionFromRequiredVersion(requiredVersion) is only used as a last-resort fallback.

Provider version now resolves in this order:

  1. Explicit shared version
  2. Installed package version from package.json
  3. Version inferred from requiredVersion

Problem

Previously, normalizeShareItem() treated the inferred requiredVersion value as part of the explicit version path:

const explicitVersion =
  typeof shareItem === 'object'
    ? shareItem.version || inferVersionFromRequiredVersion(shareItem.requiredVersion)
    : undefined;

const version = explicitVersion || searchPackageVersion(key);

With [email protected] installed and requiredVersion: '^19.1.1', the generated shared metadata advertised react as provider version 19.1.1.

requiredVersion is a consumer constraint, while version should describe the actual package version this build can provide.

Changes

  • Split explicit shared version from the inferred requiredVersion fallback.
  • Prefer searchPackageVersion(key) before using the inferred fallback.
  • Added a regression test for installed [email protected] with requiredVersion: '^19.1.1'.

Validation

pnpm exec vitest run src/utils/__tests__/normalizeModuleFederationOption.test.ts
pnpm test
pnpm run typecheck
pnpm run fmt.check
pnpm run build

Results:

  • src/utils/__tests__/normalizeModuleFederationOption.test.ts: 30 passed
  • pnpm test: 34 files, 520 tests passed
  • typecheck: passed
  • fmt.check: passed
  • build: passed

@pkg-pr-new

pkg-pr-new Bot commented Jun 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: b8c816a

@gioboa

gioboa commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Fixes shared version precedence so the installed package version is preferred over a version inferred from requiredVersion.

Example: if [email protected] is installed and shared config has requiredVersion: '^19.1.1', the manifest now advertises provider version: '19.2.7' instead of incorrectly inferring version: '19.1.1'.

requiredVersion remains the consumer constraint; version now reflects what the build actually provides.

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

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 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @dmchoi77
Nice catch πŸ‘ that's a great find.

@gioboa gioboa merged commit ef9a8c4 into module-federation:main Jun 16, 2026
19 checks passed
@dmchoi77

Copy link
Copy Markdown
Contributor Author

@gioboa Thanks! Glad it helped πŸ˜„

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.

[Bug]: shared requiredVersion is inferred as provider version before installed package version

2 participants