Skip to content

fix(module-federation): strip version suffix from npm dependency names for bun compatibility - #34960

Merged
leosvelperez merged 3 commits into
nrwl:masterfrom
theescodes:fix/module-federation-bun-dependency-names
Jul 17, 2026
Merged

fix(module-federation): strip version suffix from npm dependency names for bun compatibility#34960
leosvelperez merged 3 commits into
nrwl:masterfrom
theescodes:fix/module-federation-bun-dependency-names

Conversation

@theescodes

@theescodes theescodes commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Current Behavior

When using Bun as the package manager, the Nx project graph includes version numbers in external node dependency targets (e.g., npm:@ngrx/store@21.0.1), whereas npm uses npm:@ngrx/store (without version).

The collectDependencies function in packages/module-federation/src/utils/dependencies.ts strips the npm: prefix but not the version suffix, resulting in package names like @ngrx/store@21.0.1 being passed to sharePackages(). These fail to match entries in package.json (which uses @ngrx/store), so no npm packages are shared between Module Federation host and remotes, causing runtime errors such as:

NG0201: No provider found for InjectionToken @ngrx/store Root Store Provider

Expected Behavior

The version suffix is stripped from npm dependency names before they are added to the shared packages set. For example:

  • @ngrx/store@21.0.1 -> @ngrx/store
  • rxjs@7.8.1 -> rxjs
  • lodash (no version) -> lodash (unchanged)

This ensures shared packages are correctly resolved regardless of the package manager (npm, pnpm, yarn, or bun).

Related Issue(s)

#35135

@theescodes
theescodes requested a review from a team as a code owner March 23, 2026 09:58
@theescodes
theescodes requested a review from FrozenPandaz March 23, 2026 09:58
@netlify

netlify Bot commented Mar 23, 2026

Copy link
Copy Markdown

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 364ab9e

@netlify

netlify Bot commented Mar 23, 2026

Copy link
Copy Markdown

👷 Deploy request for nx-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 364ab9e

@theescodes
theescodes force-pushed the fix/module-federation-bun-dependency-names branch from 7903b1d to 92db7c0 Compare March 25, 2026 17:52
@theescodes
theescodes force-pushed the fix/module-federation-bun-dependency-names branch from 9c1d129 to 1eea8b7 Compare April 1, 2026 18:32
@nx-cloud

nx-cloud Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 364ab9e

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 49m 50s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 36s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 13s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 4s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-17 14:10:32 UTC

@leosvelperez leosvelperez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@leosvelperez
leosvelperez merged commit 2ecb611 into nrwl:master Jul 17, 2026
17 checks passed
FrozenPandaz pushed a commit that referenced this pull request Jul 20, 2026
…s for bun compatibility (#34960)

## Current Behavior

When using Bun as the package manager, the Nx project graph includes
version numbers in external node dependency targets (e.g.,
`npm:@ngrx/store@21.0.1`), whereas npm uses `npm:@ngrx/store` (without
version).

The `collectDependencies` function in
`packages/module-federation/src/utils/dependencies.ts` strips the `npm:`
prefix but not the version suffix, resulting in package names like
`@ngrx/store@21.0.1` being passed to `sharePackages()`. These fail to
match entries in `package.json` (which uses `@ngrx/store`), so **no npm
packages are shared** between Module Federation host and remotes,
causing runtime errors such as:

```
NG0201: No provider found for InjectionToken @ngrx/store Root Store Provider
```

## Expected Behavior

The version suffix is stripped from npm dependency names before they are
added to the shared packages set. For example:
- `@ngrx/store@21.0.1` -> `@ngrx/store`
- `rxjs@7.8.1` -> `rxjs`
- `lodash` (no version) -> `lodash` (unchanged)

This ensures shared packages are correctly resolved regardless of the
package manager (npm, pnpm, yarn, or bun).

## Related Issue(s)

#35135

Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>
(cherry picked from commit 2ecb611)
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