Skip to content

fix: expose exports of all entry modules in library output - #21662

Closed
webdevelopersrinu wants to merge 1 commit into
webpack:mainfrom
webdevelopersrinu:fix-15936-library-entry-array-exports
Closed

webdevelopersrinu wants to merge 1 commit into
webpack:mainfrom
webdevelopersrinu:fix-15936-library-entry-array-exports

Conversation

@webdevelopersrinu

@webdevelopersrinu webdevelopersrinu commented Aug 10, 2026 •

Copy link
Copy Markdown

Fixes #15936

Note: supersedes #21661, which was auto-closed by the quality bot before my CLA signature had processed. CLA is now signed, the changeset is included, and CodeRabbit's review feedback from that PR has been addressed in this one.

Problem

With entry: ["./a.js", "./b.js", "./c.js"] and a library output, only the last entry module's exports were flagged as used — exports of earlier entries were tree-shaken away and silently dropped from the library.

Solution (library plugin layer only)

  • AbstractLibraryPlugin gains an opt-in finishAllEntryModules mode that flags exports of every entry dependency as used, plus a helper that renders startup code merging all entry modules' exports into the library exports object.
  • AssignLibraryPlugin (var/assign/this/window/self/global/commonjs/commonjs2) and ExportPropertyLibraryPlugin (amd/umd/system/jsonp) opt in.
  • Later entries win on export name conflicts — preserving the documented "last entry wins" semantics for conflicting names.
  • module/modern-module and commonjs-static intentionally keep current behavior (their export lists are generated statically from the last entry module).
  • Merging is skipped when startup is delayed by depending chunks or when entry modules are inlined; single-entry output is byte-identical to before.

Testing

  • New test case test/configCases/library/issue-15936-entry-array-exports — fails on main, passes with this change (multi-entry exposure + conflict semantics).
  • Full library category of ConfigTestCases: zero new failures vs baseline.
  • Includes a changeset (patch).

Summary by CodeRabbit

  • New Features

    • Library bundles with multiple entry points now expose exports from all entry modules.
    • When export names conflict, the value from the later entry module takes precedence.
  • Bug Fixes

    • Fixed incomplete exports in libraries configured with array-based entry points.
  • Tests

    • Added coverage for combined exports and conflicting export names across multiple entries.
  • Documentation

    • Added a release note describing the multi-entry export improvement.

When an entry is an array of modules and a library output is configured,
only the exports of the last entry module were flagged as used and
exposed on the library. Exports of all earlier entry modules were
tree-shaken away and silently dropped.

The fix stays entirely in the library plugin layer:

- AbstractLibraryPlugin gains an opt-in finishAllEntryModules mode that
  flags the exports of every entry dependency as used, and a helper that
  renders startup code merging the exports of all entry modules of the
  chunk into the final library exports object. Later entry modules win
  on export name conflicts, preserving the documented last-entry-wins
  semantics. Merging is skipped when startup is delayed by depending
  chunks or when entry modules are inlined.
- AssignLibraryPlugin (var, assign, this, window, self, global,
  commonjs, commonjs2) and ExportPropertyLibraryPlugin (amd, umd,
  system, jsonp) opt in.
- module/modern-module and commonjs-static keep their current behavior,
  since their export lists are generated statically from the last entry
  module.

Fixes webpack#15936
@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a4dc34f

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

@github-actions github-actions Bot added the area: types types.d.ts, JSDoc annotations, hand-maintained declarations label Aug 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi there! This PR was automatically flagged and closed by our quality checks.

If you believe this was a mistake, please review our contributing guidelines
and leave a comment explaining why this is a mistake.

@github-actions github-actions Bot closed this Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7886fe96-acd1-4100-a0e2-04e6e76f60b5

📥 Commits

Reviewing files that changed from the base of the PR and between e3f177c and a4dc34f.

⛔ Files ignored due to path filters (1)
  • types.d.ts is excluded by !types.d.ts
📒 Files selected for processing (8)
  • .changeset/multi-entry-library-exports.md
  • lib/library/AbstractLibraryPlugin.js
  • lib/library/AssignLibraryPlugin.js
  • lib/library/ExportPropertyLibraryPlugin.js
  • test/configCases/library/issue-15936-entry-array-exports/a.js
  • test/configCases/library/issue-15936-entry-array-exports/b.js
  • test/configCases/library/issue-15936-entry-array-exports/index.js
  • test/configCases/library/issue-15936-entry-array-exports/webpack.config.js

📝 Walkthrough

Walkthrough

Changes

The library plugins now merge exports from all eligible synchronous modules in an array entry. Later modules override earlier exports with the same name. A regression case validates aggregation and precedence.

Multi-entry library exports

Layer / File(s) Summary
Entry export merge core
lib/library/AbstractLibraryPlugin.js
Adds configurable processing for all entry modules, mergeable-entry detection, generated export-merging runtime code, and runtime requirements.
Library plugin wiring
lib/library/AssignLibraryPlugin.js, lib/library/ExportPropertyLibraryPlugin.js
Enables merging for applicable library types and combines the merge output with existing startup and export-property handling.
Regression validation and release note
test/configCases/library/issue-15936-entry-array-exports/*, .changeset/multi-entry-library-exports.md
Tests exports from all three entries and confirms that the later shared export takes precedence. Records a patch release.

Fixed issue severity: Medium

Possibly related PRs

  • webpack/webpack#21661: Implements the same multi-entry library export merging changes in overlapping plugins and regression tests.

Comment @coderabbitai help to get the list of available commands.

@webdevelopersrinu

Copy link
Copy Markdown
Author

@alexander-akait @avivkeller I'd like to respectfully ask for a human review of this closure — I believe the quality bot is flagging my account history (new contributor, and #21661 which was closed only because my CLA hadn't processed yet), not this submission.

Everything the bot previously flagged is resolved: EasyCLA is green, the changeset is included, the commit and title follow conventional format.

On the substance: this addresses #15936 (help wanted, open since 2022). I commented my approach on the issue before implementing. Unlike the previously rejected attempts, the fix stays entirely in the library plugin layer — per your feedback on #20638 that the fix belongs in the libraries — and preserves the documented "last entry wins" semantics on conflicts. It includes a test case that fails on main and passes with the fix, and the full library ConfigTestCases category shows zero new failures vs baseline.

If there's anything about the approach you'd like changed, I'm happy to rework it. Could this be reopened for review?

@avivkeller avivkeller added the exempt [Exempt from Quality Checks] label Aug 10, 2026
@avivkeller avivkeller reopened this Aug 10, 2026
@alexander-akait

Copy link
Copy Markdown
Member

It is a breaking change, we need to make it under the option and it requires discussions firstly and compare how other tools work here, let’s close now, feel free to start a discussion in the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: types types.d.ts, JSDoc annotations, hand-maintained declarations exempt [Exempt from Quality Checks]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

export in library works only for last entry module

3 participants