Skip to content

fix: export in library works only for last entry module - #20638

Closed
kb019 wants to merge 1 commit into
webpack:mainfrom
kb019:issues/15936
Closed

kb019 wants to merge 1 commit into
webpack:mainfrom
kb019:issues/15936

Conversation

@kb019

@kb019 kb019 commented Mar 13, 2026 •

Copy link
Copy Markdown

Summary

fixes #15936

Until now when we were doing multiple imports in entry point as array, only the exports from the last entry would be available.With this PR, the exports should work for all the entry points.

What kind of change does this PR introduce?
This PR fixes the problem of exports only available from the last entry. They are fixed in three stages

1) when entry points is refrenced by other modules

Before

> ******/ 	// startup
> /******/ 	// Load entry module and return exports
> /******/ 	// This entry module is referenced by other modules so it can't be inlined
> /******/ 	__webpack_require__("./src/index.js");
> /******/ 	__webpack_require__("./src/scriptB.js");
> /******/ 	var __webpack_exports__ = __webpack_require__("./src/scriptC.js");
> /******/ 	var __webpack_export_target__ = self;
> /******/ 	for(var __webpack_i__ in __webpack_exports__) __webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
> /******/ 	if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
> /******/ 

After


> `/******/ 	
> /******/ 	// startup
> /******/ 	// Load entry module and return exports
> /******/ 	// This entry module is referenced by other modules so it can't be inlined
> /******/ 	var __webpack_exports__ = __webpack_require__("./src/index.js");
> /******/ 	__webpack_exports__ = Object.assign({...__webpack_exports__},{...__webpack_require__("./src/scriptB.js")});
> /******/ 	__webpack_exports__ = Object.assign({...__webpack_exports__},{...__webpack_require__("./src/scriptC.js")});
> /******/ 	var __webpack_export_target__ = self;
> /******/ 	for(var __webpack_i__ in __webpack_exports__) __webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
> /******/ 	if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
> /******/ 	
> /******/ })()`

2) When entry points depend on other chunks

Before

> /******/ 	// startup
> /******/ 	// Load entry module and return exports
> /******/ 	// This entry module depends on other loaded chunks and execution need to be delayed
> /******/ 	__webpack_require__.O(undefined, ["vendors-node_modules_jquery_dist_jquery_js"], () => (__webpack_require__("./src/index.js")))
> /******/ 	__webpack_require__.O(undefined, ["vendors-node_modules_jquery_dist_jquery_js"], () => (__webpack_require__("./src/scriptB.js")))
> /******/ 	var __webpack_exports__ = __webpack_require__.O(undefined, ["vendors-node_modules_jquery_dist_jquery_js"], () => (__webpack_require__("./src/scriptC.js")))
> /******/ 	__webpack_exports__ = __webpack_require__.O(__webpack_exports__);
> /******/ 	var __webpack_export_target__ = self;
> /******/ 	for(var __webpack_i__ in __webpack_exports__) __webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
> /******/ 	if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
> /******/ 

After

> /******/ 	// startup
> /******/ 	// Load entry module and return exports
> /******/ 	// This entry module depends on other loaded chunks and execution need to be delayed
> /******/ 	var __webpack_exports__ = __webpack_require__.O(undefined, ["vendors-node_modules_jquery_dist_jquery_js"], () => (__webpack_require__("./src/index.js")))
> /******/ 	__webpack_exports__ = Object.assign({...__webpack_exports__},{...__webpack_require__.O(__webpack_exports__)});
> /******/ 	__webpack_require__.O(undefined, ["vendors-node_modules_jquery_dist_jquery_js"], () => (__webpack_require__("./src/scriptB.js")))
> /******/ 	__webpack_exports__ = Object.assign({...__webpack_exports__},{...__webpack_require__.O(__webpack_exports__)});
> /******/ 	__webpack_require__.O(undefined, ["vendors-node_modules_jquery_dist_jquery_js"], () => (__webpack_require__("./src/scriptC.js")))
> /******/ 	__webpack_exports__ = Object.assign({...__webpack_exports__},{...__webpack_require__.O(__webpack_exports__)});
> /******/ 	__webpack_exports__ = __webpack_require__.O(__webpack_exports__);
> /******/ 	var __webpack_export_target__ = self;
> /******/ 	for(var __webpack_i__ in __webpack_exports__) __webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
> /******/ 	if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
> /******/ 	

3) When there are Inline entry modules

In this case , i avoid writing the exports variable inside iife for inline entry modules, this way all the entry modules use the global exports variable and thus exports from all extry points would be available.

Did you add tests for your changes?
yes i have added tests

Does this PR introduce a breaking change?
No Breaking Change

If relevant, what needs to be documented once your changes are merged or what have you already documented?
Since exports from all the entry points will be available, we have to update the document in places where it says only exports
from last entry point will be available like here.

Use of AI

I have never used AI for this PR, it took me literally a week to understand and come to this solution.

@changeset-bot

changeset-bot Bot commented Mar 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 64a2641

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

@linux-foundation-easycla

linux-foundation-easycla Bot commented Mar 13, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: kb019 / name: Bhargav kodali (64a2641)

@alexander-akait alexander-akait 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.

This is wrong solution and the issue about libraries

@kb019

kb019 commented Mar 13, 2026

Copy link
Copy Markdown
Author

Ho @alexander-akait , could you please guide me in right direction on how to solve this issue.

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

2 participants