GeezerVison is showing github.com — fix(config): default output.module to true when using module library type by Pcmhacker-piro · Pull Request #22063 · webpack/webpack
Conversation
Pcmhacker-piro
commented
Sep 11, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
Following the removal of experiments.outputModule in #22011, output.module should default to true whenever an ESM output is configured.
Previously, output.module only defaulted to true when targeting universal, deno, or bun (tp.node === null && tp.web === null && tp.module !== false, tp.deno === true, tp.bun === true). If a user configured output.library.type: "module" or "modern-module" (or set it per-entry in entry[name].library.type: "module"), output.module remained false.
As a consequence:
output.iife defaulted to true (because !output.module).
- Webpack wrapped the output in an IIFE
(() => { ... })().
ModuleLibraryPlugin emitted export default ... inside the IIFE body:
(() => {
// ...
export default __webpack_exports__;
})();
- This emitted invalid JavaScript syntax, throwing a runtime
SyntaxError: Unexpected token 'export' and failing Terser minification in production ("Export" statement may only appear at the top level).
- Furthermore, configuring
output: { module: false, library: { type: "module" } } was not guarded, allowing conflicting options to produce invalid code silently.
This PR:
- Defaults
output.module to true in lib/config/defaults.js when output.library.type or any entry[name].library.type is "module" or "modern-module".
- Adds an explicit error in
lib/WebpackOptionsApply.js when !output.module but library type "module" or "modern-module" is enabled: library type "<type>" is only allowed when 'output.module' is enabled.
- Updates
test/harness/runner/index.js so .mjs runner tests with module library types are correctly dispatched to ESM execution.
Fixes #22061.
What kind of change does this PR introduce?
bugfix
Did you add tests for your changes?
Yes:
- Unit tests in
test/Defaults.unittest.js testing that output.module defaults to true for output.library.type: "module", "modern-module", and entry[name].library.type: "module", and tests that a descriptive error is thrown when output.module: false with module library types.
- Integration config test in
test/configCases/library/module-default-output-module/ verifying compilation and ESM execution without manually setting output.module: true.
Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Documentation for output.library.type: "module" can note that output.module is automatically enabled.
Use of AI
Yes
Summary by CodeRabbit
- New Features
- Module output is now enabled by default when using the
module or modern-module library types, including per-entry libraries.
- ES module libraries can now be used without explicitly setting module output.
- Bug Fixes
- Added clear validation errors when module library types are configured with module output disabled.
- Improved handling of
.mjs library bundles so they run correctly as ES modules in supported environments.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…type
When output.library.type (or an entry library.type) is set to 'module' or 'modern-module', output.module must default to true so that webpack does not emit export statements wrapped inside an IIFE.
Also throws a descriptive configuration error if output.module is explicitly set to false with a module library type.
Fixes webpack#22061.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
👋 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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Sep 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
 
Caution
Review failed
The pull request is closed.
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID: 6d94bf5d-620e-4ea7-bdb4-2318df26d1f4
📥 Commits
Reviewing files that changed from the base of the PR and between 3a69d29 and e0d04f2.
📒 Files selected for processing (9)
.changeset/008-library-module-output-default.md
lib/WebpackOptionsApply.js
lib/config/defaults.js
test/Defaults.unittest.js
test/configCases/library/module-default-output-module/dep.js
test/configCases/library/module-default-output-module/index.js
test/configCases/library/module-default-output-module/test.config.js
test/configCases/library/module-default-output-module/webpack.config.js
test/harness/runner/index.js
📝 Walkthrough
Walkthrough
Webpack now defaults output.module to true for "module" and "modern-module" library types. It rejects explicit incompatible settings and adds unit, configuration-case, and ESM runner coverage.
Changes
Module library output
| Layer / File(s) |
Summary |
Module output defaults lib/config/defaults.js |
Module output detection covers top-level and entry-level "module" and "modern-module" libraries. The shared entry iterator replaces a duplicate helper. |
Incompatible output validation lib/WebpackOptionsApply.js, .changeset/008-library-module-output-default.md |
Webpack throws when these library types are combined with output.module: false. The changeset records the patch. |
Configuration and runner coverage test/Defaults.unittest.js, test/configCases/library/module-default-output-module/*, test/harness/runner/index.js |
Tests verify defaults, validation errors, emitted module execution, and .mjs ESM runner selection. |
Suggested reviewers: alexander-akait
Change: Bug fix · Severity of issue fixed: Medium
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@alexander-akait @avivkeller I'd like to respectfully ask for a human review to reopen this PR — the automated quality check flagged 'max-daily-forks' on my GitHub account activity, not the content of this PR.
This PR addresses #22061 (where output.library.type: 'module' defaults output.module to false, emitting invalid JavaScript with an export statement wrapped inside an IIFE).
- EasyCLA is signed and passing.
- All code/commit quality checks passed (conventional commit format, commit author match, newline, etc.).
- Unit tests added in
test/Defaults.unittest.js and an end-to-end integration test in test/configCases/library/module-default-output-module/.
- Valid patch changeset included in
.changeset/008-library-module-output-default.md.
- All linters, formatting, and spell checks pass cleanly.
Could a maintainer please reopen this PR for review? Thank you!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
User created 8 fork(s) in a 24-hour window, exceeds maximum of 4
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Please in future avoid to duplicate PRs, also our actions properly found out that this job was just AI generated, please prefer be more human and keep answering by hands rather than only AI generated, thanks for helping us
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
area: config
Options, defaults, validation (lib/config, schemas/)
exempt
[Exempt from Quality Checks]
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|