Skip to content

fix(enhanced): implement getSourceBasicTypes for ConsumeSharedModule#4563

Merged
2heal1 merged 3 commits intomodule-federation:mainfrom
2heal1:fix/consume-shared-module-webpack-5105
Mar 18, 2026
Merged

fix(enhanced): implement getSourceBasicTypes for ConsumeSharedModule#4563
2heal1 merged 3 commits intomodule-federation:mainfrom
2heal1:fix/consume-shared-module-webpack-5105

Conversation

@2heal1
Copy link
Copy Markdown
Member

@2heal1 2heal1 commented Mar 18, 2026

Context

Webpack 5.105.4 introduced Module#getSourceBasicTypes() (webpack/webpack#20546) and updated ModuleConcatenationPlugin / ConcatenatedModule.findTarget() to use it as the canonical filter for detecting whether a module produces JavaScript output.

Two modules in @module-federation/enhanced were affected:

  • ConsumeSharedModule: getSourceTypes() returns ["consume-shared"], a non-basic type. Without overriding getSourceBasicTypes(), it gets treated as non-JS and filtered out during scope hoisting.
  • RemoteModule: getSourceTypes() returns ["remote", "share-init"], also non-basic types. Same issue applies — it would be incorrectly excluded from JS-only optimisation paths.

Both modules produce JavaScript output, so their getSourceBasicTypes() should correctly return Set(["javascript"]).

What changed

  • Added getSourceBasicTypes() to packages/enhanced/src/lib/sharing/ConsumeSharedModule.ts, returning Set(["javascript"]).
  • Added getSourceBasicTypes() to packages/enhanced/src/lib/container/RemoteModule.ts, returning Set(["javascript"]).
  • Added unit tests to assert the behavior.

Why

This restores compatibility with Webpack 5.105.4+ while remaining safe for older webpack versions (the method is simply ignored by older runtimes).

Validation

  • pnpm install --frozen-lockfile
  • pnpm --filter @module-federation/enhanced run build

Reference

Closes #4559

Webpack 5.105.4 introduced `Module#getSourceBasicTypes()` and added a JavaScript-only filter inside ModuleConcatenationPlugin.

`@module-federation/enhanced`'s ConsumeSharedModule only defined `getSourceTypes()` (returning `consume-shared`), which causes `getSourceBasicTypes()` to fall back to the wrong set and breaks scope hoisting / re-export target resolution.

This change adds `getSourceBasicTypes()` returning `new Set(["javascript"])`, matching webpack core's ConsumeSharedModule behavior, and adds a focused unit test.

Refs: module-federation#4559
Co-Authored-By: Aime <aime@bytedance.com>
Change-Id: Ic62a58c908d85b3152f8de6cdb96d903573f8be9
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 18, 2026

⚠️ No Changeset found

Latest commit: 78e5a71

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 18, 2026

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 78e5a71
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/69ba24ad5c2f53000809b1e2
😎 Deploy Preview https://deploy-preview-4563--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 18, 2026

Open in StackBlitz

@module-federation/devtools

pnpm add https://pkg.pr.new/@module-federation/devtools@78e5a71

@module-federation/cli

pnpm add https://pkg.pr.new/@module-federation/cli@78e5a71

create-module-federation

pnpm add https://pkg.pr.new/create-module-federation@78e5a71

@module-federation/data-prefetch

pnpm add https://pkg.pr.new/@module-federation/data-prefetch@78e5a71

@module-federation/dts-plugin

pnpm add https://pkg.pr.new/@module-federation/dts-plugin@78e5a71

@module-federation/enhanced

pnpm add https://pkg.pr.new/@module-federation/enhanced@78e5a71

@module-federation/error-codes

pnpm add https://pkg.pr.new/@module-federation/error-codes@78e5a71

@module-federation/esbuild

pnpm add https://pkg.pr.new/@module-federation/esbuild@78e5a71

@module-federation/managers

pnpm add https://pkg.pr.new/@module-federation/managers@78e5a71

@module-federation/manifest

pnpm add https://pkg.pr.new/@module-federation/manifest@78e5a71

@module-federation/metro

pnpm add https://pkg.pr.new/@module-federation/metro@78e5a71

@module-federation/metro-plugin-rnc-cli

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnc-cli@78e5a71

@module-federation/metro-plugin-rnef

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnef@78e5a71

@module-federation/modern-js

pnpm add https://pkg.pr.new/@module-federation/modern-js@78e5a71

@module-federation/modern-js-v3

pnpm add https://pkg.pr.new/@module-federation/modern-js-v3@78e5a71

@module-federation/native-federation-tests

pnpm add https://pkg.pr.new/@module-federation/native-federation-tests@78e5a71

@module-federation/native-federation-typescript

pnpm add https://pkg.pr.new/@module-federation/native-federation-typescript@78e5a71

@module-federation/nextjs-mf

pnpm add https://pkg.pr.new/@module-federation/nextjs-mf@78e5a71

@module-federation/node

pnpm add https://pkg.pr.new/@module-federation/node@78e5a71

@module-federation/retry-plugin

pnpm add https://pkg.pr.new/@module-federation/retry-plugin@78e5a71

@module-federation/rsbuild-plugin

pnpm add https://pkg.pr.new/@module-federation/rsbuild-plugin@78e5a71

@module-federation/rspack

pnpm add https://pkg.pr.new/@module-federation/rspack@78e5a71

@module-federation/rspress-plugin

pnpm add https://pkg.pr.new/@module-federation/rspress-plugin@78e5a71

@module-federation/runtime

pnpm add https://pkg.pr.new/@module-federation/runtime@78e5a71

@module-federation/runtime-core

pnpm add https://pkg.pr.new/@module-federation/runtime-core@78e5a71

@module-federation/runtime-tools

pnpm add https://pkg.pr.new/@module-federation/runtime-tools@78e5a71

@module-federation/sdk

pnpm add https://pkg.pr.new/@module-federation/sdk@78e5a71

@module-federation/storybook-addon

pnpm add https://pkg.pr.new/@module-federation/storybook-addon@78e5a71

@module-federation/third-party-dts-extractor

pnpm add https://pkg.pr.new/@module-federation/third-party-dts-extractor@78e5a71

@module-federation/treeshake-frontend

pnpm add https://pkg.pr.new/@module-federation/treeshake-frontend@78e5a71

@module-federation/treeshake-server

pnpm add https://pkg.pr.new/@module-federation/treeshake-server@78e5a71

@module-federation/typescript

pnpm add https://pkg.pr.new/@module-federation/typescript@78e5a71

@module-federation/utilities

pnpm add https://pkg.pr.new/@module-federation/utilities@78e5a71

@module-federation/webpack-bundler-runtime

pnpm add https://pkg.pr.new/@module-federation/webpack-bundler-runtime@78e5a71

@module-federation/bridge-react

pnpm add https://pkg.pr.new/@module-federation/bridge-react@78e5a71

@module-federation/bridge-react-webpack-plugin

pnpm add https://pkg.pr.new/@module-federation/bridge-react-webpack-plugin@78e5a71

@module-federation/bridge-shared

pnpm add https://pkg.pr.new/@module-federation/bridge-shared@78e5a71

@module-federation/bridge-vue3

pnpm add https://pkg.pr.new/@module-federation/bridge-vue3@78e5a71

@module-federation/inject-external-runtime-core-plugin

pnpm add https://pkg.pr.new/@module-federation/inject-external-runtime-core-plugin@78e5a71

commit: 78e5a71

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 18, 2026

Bundle Size Report

10 package(s) changed, 30 unchanged.

Package dist + ESM entry

Package Total dist (raw) Delta ESM gzip Delta
@module-federation/cli 26.7 kB no change 786 B no change
@module-federation/core 39.1 kB no change 173 B no change
@module-federation/devtools 473.2 kB no change 3.9 kB no change
@module-federation/enhanced 810.5 kB +425 B (+0.1%) 672 B no change
@module-federation/managers 69.9 kB no change 334 B no change
@module-federation/manifest 138.4 kB no change 182 B no change
@module-federation/metro-plugin-rnc-cli 0 B no change 314 B no change
@module-federation/node 189.2 kB no change 217 B no change
@module-federation/storybook-addon 77.0 kB no change 100 B no change
@module-federation/utilities 110.6 kB no change 328 B no change

Bundle targets

Package Web bundle (gzip) Delta Node bundle (gzip) Delta
@module-federation/cli 2.3 kB -33 B (-1.4%) 2.3 kB -33 B (-1.4%)
@module-federation/core 1.1 kB -31 B (-2.8%) 1.0 kB -30 B (-2.8%)
@module-federation/devtools 20.8 kB -25 B (-0.1%) 20.8 kB -25 B (-0.1%)
@module-federation/enhanced 2.6 kB -43 B (-1.6%) 2.6 kB -43 B (-1.6%)
@module-federation/managers 2.4 kB -26 B (-1.0%) 2.4 kB -26 B (-1.0%)
@module-federation/manifest 6.2 kB -37 B (-0.6%) 6.2 kB -37 B (-0.6%)
@module-federation/metro-plugin-rnc-cli 411 B -25 B (-5.7%) 411 B -25 B (-5.7%)
@module-federation/node 9.2 kB -27 B (-0.3%) 9.2 kB -27 B (-0.3%)
@module-federation/storybook-addon 1.9 kB -24 B (-1.2%) 1.7 kB -24 B (-1.3%)
@module-federation/utilities 2.6 kB -31 B (-1.2%) 2.6 kB -31 B (-1.2%)

Consumer scenarios

Scenario Web output (gzip) Delta Node output (gzip) Delta Gap (node-web) Delta
Enhanced remoteEntry 19.5 kB -18 B (-0.1%) 20.5 kB -16 B (-0.1%) +1.0 kB +2 B

Total dist (raw): 6.31 MB (+425 B (+0.0%))
Total ESM gzip: 73.4 kB (no change)
Total web bundle (gzip): 177.8 kB (-302 B (-0.2%))
Total node bundle (gzip): 178.3 kB (-301 B (-0.2%))
Tracked ./bundler entry gzip: 556 B (no change)
Tracked ./bundler web bundle (gzip): 4.5 kB (no change)
Tracked ./bundler node bundle (gzip): 4.5 kB (no change)

Bundle sizes are generated with rslib (Rspack). Package-root metrics preserve the historical report. Tracked subpath exports such as ./bundler are measured separately so ENV_TARGET-driven tree-shaking is visible. Bare imports are externalized to keep package-level sizes consistent, and assets are emitted as resources.

2heal1 and others added 2 commits March 18, 2026 11:40
Implements `RemoteModule.getSourceBasicTypes()` in `@module-federation/enhanced`, mirroring Webpack PR #20546 behavior to keep module source-type filtering consistent with newer Webpack internals.

Validation:
- `pnpm --filter @module-federation/enhanced run build`

Co-Authored-By: Aime <aime@bytedance.com>
Change-Id: I0120d6c755e73c6dd1bbe6bd15af93a1641c2c60
- Update ConsumeSharedModule#getSourceBasicTypes to be declared with `override` keyword
- Keep method body unchanged and align with other overridden methods in the same class
- Verified build with `pnpm --filter @module-federation/enhanced run build`

Co-Authored-By: Aime <aime@bytedance.com>
Change-Id: I3cc9f3e9e82d740211cf7973bf56a9d9d5851ec5
@2heal1 2heal1 merged commit 6860918 into module-federation:main Mar 18, 2026
23 checks passed
@2heal1 2heal1 mentioned this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConsumeSharedModule missing getSourceBasicTypes() causes crash with webpack 5.105.4

1 participant