-
-
Notifications
You must be signed in to change notification settings - Fork 370
fix(webpack-bundler-runtime): fix the bug that mjs is wrongly handled #4239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(webpack-bundler-runtime): fix the bug that mjs is wrongly handled #4239
Conversation
🦋 Changeset detectedLatest commit: eb21d4c The changes in this PR will be included in the next version bump. This PR includes changesets to release 37 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| shareInfo?.shareConfig?.layer && | ||
| result && | ||
| typeof result === 'object' | ||
| moduleExports && | ||
| typeof moduleExports === 'object' | ||
| ) { | ||
| try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip layer tagging for function defaults after unwrapping
When a shared module is configured with shareConfig.layer and its default export is a function/object, the new unwrapping logic sets moduleExports to that function but the layer attachment block now requires typeof moduleExports === 'object', so the layer property is never added. Previously the layer metadata was applied to the namespace object and was available to consumers. With this change, layered shares backed by a function default lose their layer tag entirely, breaking layer-aware consumers for exactly the remotes/shared combination this commit targets.
Useful? React with 👍 / 👎.
| if ( | ||
| shareInfo?.shareConfig?.layer && | ||
| result && | ||
| typeof result === 'object' | ||
| moduleExports && | ||
| typeof moduleExports === 'object' | ||
| ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eager consumes drop layer metadata when default export is a function
The eager path mirrors the same typeof moduleExports === 'object' guard before assigning shareConfig.layer. After unwrapping an ESM namespace to its default function, this condition is false, so layered shares no longer receive the layer property. Earlier versions always set the layer on the returned namespace object, so this is a regression for any layered shared module whose default export is a function/object.
Useful? React with 👍 / 👎.
a7b3521 to
ef448c7
Compare
… mjs files Fix ESM interop issue where .mjs files received module namespace objects instead of default exports when using Module Federation with remotes. The runtime now intelligently unwraps ESM namespace objects for object/function default exports while preserving the namespace for primitive defaults to maintain named export accessibility.
ef448c7 to
eb21d4c
Compare
Description
When using Module Federation with both remotes AND shared modules, .mjs files that import a default export from a shared module receive the module namespace object instead of the default export value.
See #4238 more in detail.
The solution to this problem is:
Testing with the reproduction codes,

Related Issue
#4238
Types of changes
Checklist