Skip to content

fix: expose exports from all entry modules in library output#20731

Open
sujalgoel wants to merge 1 commit intowebpack:mainfrom
sujalgoel:fix/library-multi-entry-exports
Open

fix: expose exports from all entry modules in library output#20731
sujalgoel wants to merge 1 commit intowebpack:mainfrom
sujalgoel:fix/library-multi-entry-exports

Conversation

@sujalgoel
Copy link
Copy Markdown

Summary

Fixes #15936

When using an array entry with output.library, only the last entry module's exports were accessible on the library object. The remaining entry modules had their exports silently discarded.

Root cause

Two separate issues:

  1. AbstractLibraryPlugin (lib/library/AbstractLibraryPlugin.js): finishEntryModule was only called for the last dependency in the entry deps array instead of all of them.

  2. JavascriptModulesPlugin (lib/javascript/JavascriptModulesPlugin.js): Non-last inlined entry modules were given an isolated {} as their exportsArgument, so their exports never merged into __webpack_exports__. With a library config and multiple entries, all entry modules now share the same __webpack_exports__ object.

Fix

  • Loop over all entry deps in AbstractLibraryPlugin.finishEntryModule
  • Introduce mergeLibraryEntryExports flag — when a library is configured with multiple entries, all inlined entry modules share RuntimeGlobals.exports instead of {}

Test

Added test/configCases/library/issue-15936/ which bundles three entry files (a.js, b.js, c.js) with output.library: { type: "assign", name: "MultiEntryLib" } and asserts that exports from all three are present on the global library object.

When using array entry with output.library, only the last entry's exports
were accessible on the library object. Loop over all entry deps in
AbstractLibraryPlugin and share the same __webpack_exports__ object across
all inlined entry modules so every export is merged into the library.

Fixes webpack#15936
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 28, 2026

🦋 Changeset detected

Latest commit: eb214cd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack Patch

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

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.

export in library works only for last entry module

1 participant