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

Skip to content

Conversation

@adwait1290
Copy link
Contributor

@adwait1290 adwait1290 commented Dec 7, 2025

Current Behavior

When using pnpm with workspace protocol (workspace:*, workspace:^, etc.), module federation sets requiredVersion to the raw protocol string (e.g., workspace:*) instead of resolving it to the actual semver version from the library's package.json.

This causes issues like:

  • requiredVersion: "workspace:*" which is not a valid semver
  • Module federation failing to properly share workspace libraries
  • Warnings about unable to find required versions

Example of the broken output:

{
  "version": "*",
  "singleton": true,
  "requiredVersion": "^*"
}

Expected Behavior

When a workspace protocol version is detected, it should be resolved to the actual version from the library's package.json:

{
  "version": "2.0.0",
  "singleton": true,
  "requiredVersion": "2.0.0"
}

Changes Made

  1. Added helper functions in share.ts:

    • isWorkspaceProtocolVersion() - Detects workspace protocol versions (workspace:*, workspace:^, *, file:)
    • normalizeWorkspaceProtocolVersion() - Resolves protocol versions to actual semver by looking up the library's package.json
  2. Applied normalization in shareWorkspaceLibraries():

    • After getting version from getDependencyVersionFromPackageJson, normalize it if it's a workspace protocol
    • Simplified the workspaceLibrariesAsDeps loop by using the helper function (removed duplicated logic)
  3. Updated getNpmPackageSharedConfig():

    • Added a check to warn and return undefined when workspace protocol versions are passed
    • Helps users understand that workspace libraries should be configured properly
  4. Added comprehensive tests (13 new tests):

    • 6 tests for workspace protocol version normalization in shareWorkspaceLibraries
    • 7 tests for getNpmPackageSharedConfig handling workspace protocol versions

Related Issue(s)

Fixes #31397

Merge Dependencies

This PR has no dependencies and can be merged independently.

Must be merged BEFORE: #33734


…iredVersion

When using pnpm with workspace protocol (workspace:*, workspace:^, etc.),
module federation was setting requiredVersion to the raw protocol string
instead of resolving it to the actual version from the library's package.json.

This change:
- Adds helper functions to detect and normalize workspace protocol versions
- Applies normalization in shareWorkspaceLibraries() after getting versions
- Adds warning in getNpmPackageSharedConfig() for workspace protocol versions
- Adds comprehensive tests for the new functionality

Fixes nrwl#31397
@adwait1290 adwait1290 requested a review from a team as a code owner December 7, 2025 22:34
@adwait1290 adwait1290 requested a review from Coly010 December 7, 2025 22:34
@netlify
Copy link

netlify bot commented Dec 7, 2025

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit d43db9c

@vercel
Copy link

vercel bot commented Dec 7, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Dec 7, 2025 10:43pm

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Dec 9, 2025

View your CI Pipeline Execution ↗ for commit d43db9c

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 26m 51s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2m 40s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 12s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-09 07:35:13 UTC

@Coly010 Coly010 merged commit 68783a9 into nrwl:master Dec 9, 2025
17 of 18 checks passed
@github-actions
Copy link
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

module-federation requiredVersion/strictVersion has no affect?

2 participants