fix(esm-library): avoid duplicate __webpack_require__ export#13483
Conversation
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
Pull request overview
This PR fixes a duplicate __webpack_require__ ESM export that can occur in modern-module / ESM library output, especially when optimization.runtimeChunk: false causes entry chunks to carry runtime and be imported by other chunks.
Changes:
- Avoids adding
__webpack_require__to ESM-library chunk exports whenExportRequireRuntimeModulewill already export it. - Records the export strategy on
ChunkLinkContextduring link, and uses that metadata during render instead of scanning runtime modules. - Adds a regression
esmOutputCasestest forruntimeChunk: falsewith a shared CJS module to reproduce the duplicate-export failure.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
crates/rspack_plugin_runtime/src/helpers.rs |
Adds a shared helper to decide when module chunk loading should export __webpack_require__. |
crates/rspack_plugin_runtime/src/module_chunk_loading.rs |
Uses the shared helper to keep the export decision consistent across runtime requirements hooks. |
crates/rspack_plugin_esm_library/src/chunk_link.rs |
Extends ChunkLinkContext with exports_require_via_runtime_module metadata. |
crates/rspack_plugin_esm_library/src/link.rs |
Sets the new link metadata and prevents adding a redundant __webpack_require__ chunk export in the affected cases. |
crates/rspack_plugin_esm_library/src/render.rs |
Consumes link metadata to decide whether to emit a direct __webpack_require__ export. |
tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/shared.js |
Adds a shared CJS module used by both the entry and a dynamically imported module. |
tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/dynamic.js |
Dynamic import path that consumes the shared CJS module. |
tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/index.js |
Entry test that exports a value and triggers the problematic runtime/export interaction. |
tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/rspack.config.js |
Overrides optimization.runtimeChunk to false to reproduce the issue. |
tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt |
Captures the corrected output (single __webpack_require__ export) for regression coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merging this PR will degrade performance by 2.87%
Performance Changes
Comparing Footnotes
|
Summary
__webpack_require__tochunk_link.exportswhen module chunk loading will export it via runtime moduleChunkLinkContextduring link and let render consume link metadata instead of scanning runtime modulesesmOutputCasesregression forruntimeChunk: falsewith a shared CJS chunk, which reproduces the duplicate export failure without the fixRelated links
Checklist