Skip to content

fix: concatenated require() in require.ensure or computed target - #21907

Merged
alexander-akait merged 1 commit into
mainfrom
fix/concat-require-header-in-async-block
Sep 1, 2026
Merged

fix: concatenated require() in require.ensure or computed target#21907
alexander-akait merged 1 commit into
mainfrom
fix/concat-require-header-in-async-block

Conversation

@hai-x

@hai-x hai-x commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #21903.

In concatenation, RequireHeaderDependency skipped rendering require callee only after the paired CJS require dependency had replaced the whole call and registerReplacedRequire.

But inside a require.ensure and AMD callback, the CJS require dependency sits in the async block, which JavascriptGenerator renders it after the module's presentational dependencies, so the rendering RequireHeaderDependency can't be skipped, which cause module reference error.

Now RequireHeaderDependency rely on CommonJsRequireDependnecy#rendersAsConcatenatedReference directly, it won't introduce order issues.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes

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?

n/a

Use of AI

Yes

Summary by CodeRabbit

  • Bug Fixes

    • Fixed handling of concatenated require() calls inside asynchronous loading callbacks and computed module requests.
    • Improved replacement behavior for active and inactive module branches.
    • Preserved correct module evaluation order and exported values in affected scenarios.
  • Tests

    • Added coverage for AMD and asynchronous loading callbacks.
    • Added tests for computed requests and conditional branches involving concatenated CommonJS modules.
  • Release

    • Included in a patch release of webpack.

@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d89e7eb

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 area: parser JavaScript parsing and dependency analysis (lib/javascript, lib/dependencies) area: types types.d.ts, JSDoc annotations, hand-maintained declarations labels Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (e1eb099).

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@e1eb099
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@e1eb099
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@e1eb099

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Types Coverage

Coverage after merging fix/concat-require-header-in-async-block into main will be
99.23%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
bin
   webpack.js98.82%100%100%98.82%103
examples
   build-common.js100%100%100%100%
   buildAll.js100%100%100%100%
   examples.js100%100%100%100%
   template-common.js98.21%100%100%98.21%72
examples/custom-javascript-parser
   test.filter.js100%100%100%100%
examples/custom-javascript-parser/internals
   acorn-parse.js100%100%100%100%
   meriyah-parse.js100%100%100%100%
   oxc-parse.js100%100%100%100%
examples/markdown
   webpack.config.mjs100%100%100%100%
examples/module-federation
   test.filter.js100%100%100%100%
examples/reexport-components
   test.filter.js100%100%100%100%
examples/typescript
   test.filter.js100%100%100%100%
examples/typescript-non-erasable
   test.filter.js50%100%100%50%5
examples/virtual-modules
   test.filter.js100%100%100%100%
examples/wasm-bindgen-esm
   test.filter.js100%100%100%100%
examples/wasm-complex
   test.filter.js100%100%100%100%
examples/wasm-emscripten
   test.filter.js100%100%100%100%
examples/wasm-simple
   test.filter.js100%100%100%100%
examples/wasm-simple-source-phase
   test.filter.js100%100%100%100%
lib
   APIPlugin.js100%100%100%100%
   AsyncDependenciesBlock.js100%100%100%100%
   AutomaticPrefetchPlugin.js100%100%100%100%
   BannerPlugin.js100%100%100%100%
   Cache.js98.21%100%100%98.21%101
   CacheFacade.js100%100%100%100%
   Chunk.js99.72%100%100%99.72%42
   ChunkGraph.js100%100%100%100%
   ChunkGroup.js100%100%100%100%
   ChunkTemplate.js100%100%100%100%
   CircularModulesPlugin.js99.35%100%100%99.35%244
   CleanPlugin.js99.12%100%100%99.12%212, 232
   CodeGenerationResults.js100%100%100%100%
   CompatibilityPlugin.js100%100%100%100%
   Compilation.js98.53%100%100%98.53%1736, 2055, 2062, 2070, 2092, 2095, 3034, 3513–3514, 3546, 4380, 4413, 4466–4467, 4471, 4476, 4492–4493, 4507–4508, 4513–4514, 5036, 5062, 5872, 5904, 5921, 5939, 5955, 5970, 5995–5996, 5998, 6333, 6338, 6344, 6347, 6354, 6366, 6368, 6372, 6390, 6405, 6439, 6495, 6519, 6635, 818–819
   Compiler.js99.56%100%100%99.56%1174–1175, 1183
   ConcatenationScope.js99.03%100%100%99.03%271
   ConditionalInitFragment.js100%100%100%100%
   ConstPlugin.js100%100%100%100%
   ContextExclusionPlugin.js100%100%100%100%
   ContextModule.js99.88%100%100%99.88%1554
   ContextModuleFactory.js97.29%100%100%97.29%289, 465, 486, 491, 532, 543, 545, 549, 558–559
   ContextReplacementPlugin.js100%100%100%100%
   DefinePlugin.js99.13%100%100%99.13%1124, 197–198, 214, 233, 307
   DependenciesBlock.js100%100%100%100%
   Dependency.js98.54%100%100%98.54%498, 545
   DependencyTemplate.js100%100%100%100%
   DependencyTemplates.js100%100%100%100%
   DotenvPlugin.js98.07%100%100%98.07%395, 443, 456–457
   DynamicEntryPlugin.js100%100%100%100%
   EntryOptionPlugin.js100%100%100%100%
   EntryPlugin.js100%100%100%100%
   Entrypoint.js100%100%100%100%
   EnvironmentPlugin.js97.14%100%100%97.14%49
   ErrorHelpers.js100%100%100%100%
   EvalDevToolModulePlugin.js100%100%100%100%
   EvalSourceMapDevToolPlugin.js100%100%100%100%
   ExportsInfo.js99.26%100%100%99.26%415, 431, 763, 860, 878, 922, 927
   ExportsInfoApiPlugin.js100%100%100%100%
   ExternalModule.js98.76%100%100%98.76%1340, 1343, 590–594, 596, 756
   ExternalModuleFactoryPlugin.js100%100%100%100%
   ExternalsPlugin.js100%100%100%100%
   FileSystemInfo.js99.53%100%100%99.53%187, 2464–2465, 2468, 2479, 2490, 2501, 285, 3944, 3959, 3983
   FlagAllModulesAsUsedPlugin.js100%100%100%100%
   FlagDependencyExportsPlugin.js98.36%100%100%98.36%505, 514, 517, 521, 533
   FlagDependencyUsagePlugin.js100%100%100%100%
   FlagEntryExportAsUsedPlugin.js100%100%100%100%
   Generator.js100%100%100%100%
   HotModuleReplacementPlugin.js100%100%100%100%
   HotUpdateChunk.js100%100%100%100%
   IgnorePlugin.js100%100%100%100%
   IgnoreWarningsPlugin.js100%100%100%100%
   InitFragment.js100%100%100%100%
   JavascriptMetaInfoPlugin.js100%100%100%100%
   LazyBarrel.js100%100%100%100%
   LibraryTemplatePlugin.js100%100%100%100%
   LoaderOptionsPlugin.js100%100%100%100%
   LoaderTargetPlugin.js100%100%100%100%
   MainTemplate.js100%100%100%100%
   ManifestPlugin.js100%100%100%100%
   Module.js98.51%100%100%98.51%1317, 1322, 1382, 1396, 1458, 1467
   ModuleFactory.js100%100%100%100%
   ModuleFilenameHelpers.js98.90%100%100%98.90%111, 113
   ModuleGraph.js99.78%100%100%99.78%1180
   ModuleGraphConnection.js100%100%100%100%
   ModuleInfoHeaderPlugin.js100%100%100%100%
   ModuleNotFoundError.js100%100%100%100%
   ModuleProfile.js100%100%100%100%
   ModuleSourceTypeConstants.js100%100%100%100%
   ModuleTemplate.js100%100%100%100%
   ModuleTypeConstants.js100%100%100%100%
   MultiCompiler.js99.72%100%100%99.72%729
   MultiStats.js100%100%100%100%
   MultiWatching.js100%100%100%100%
   NoEmitOnErrorsPlugin.js100%100%100%100%
   NodeStuffPlugin.js100%100%100%100%
   NormalModule.js97.99%100%100%97.99%1040, 1043, 1060, 1077, 1325, 1359, 1375, 1830, 2126, 2131–2141, 29
   NormalModuleFactory.js99.01%100%100%99.01%1341, 1790, 1801, 1811, 1862–1864, 1871, 732, 744
   NormalModuleReplacementPlugin.js100%100%100%100%
   NullFactory.js100%100%100%100%
   OptimizationStages.js100%100%100%100%
   OptionsApply.js100%100%100%100%
   Parser.js100%100%100%100%
   PlatformPlugin.js100%100%100%100%
   PrefetchPlugin.js100%100%100%100%
   ProgressPlugin.js99.80%100%100%99.80%694
   ProvidePlugin.js100%100%100%100%
   RawModule.js100%100%100%100%
   RecordIdsPlugin.js100%100%100%100%
   RequestShortener.js100%100%100%100%
   ResolverFactory.js100%100%100%100%
   RuntimeGlobals.js100%100%100%100%
   RuntimeModule.js100%100%100%100%
   RuntimePlugin.js95.78%100%100%95.78%314, 380, 389, 392, 416, 434, 455–456, 479, 499–500, 536–537, 560, 573–574, 646, 659, 680, 699
   RuntimeTemplate.js99.63%100%100%99.63%350, 3684, 4284, 4296, 4301, 4303, 4308
   SelfModuleFactory.js100%100%100%100%
   SingleEntryPlugin.js100%100%100%100%
   SourceMapDevToolModuleOptionsPlugin.js100%100%100%100%
   SourceMapDevToolPlugin.js98.63%100%100%98.63%229, 233, 235, 429, 440, 899
   Stats.js100%100%100%100%
   Template.js100%100%100%100%
   TemplatedPathPlugin.js99.48%100%100%99.48%366–367
   UseStrictPlugin.js100%100%100%100%
   WarnCaseSensitiveModulesPlugin.js100%100%100%100%
   WarnDeprecatedOptionPlugin.js100%100%100%100%
   WarnNoModeSetPlugin.js100%100%100%100%
   WatchIgnorePlugin.js100%100%100%100%
   Watching.js100%100%100%100%
   WebpackError.js100%100%100%100%
   WebpackIsIncludedPlugin.js100%100%100%100%
   WebpackOptionsApply.js100%100%100%100%
   WebpackOptionsDefaulter.js100%100%100%100%
   buildChunkGraph.js99.87%100%100%99.87%375
   cli.js98.63%100%100%98.63%10, 117, 547, 579, 629, 903
   index.js99.73%100%100%99.73%184
   validateSchema.js94.67%100%100%94.67%100, 87, 89, 98
   webpack.js97.12%100%100%97.12%10, 274, 296, 298
lib/asset
   AssetBytesGenerator.js100%100%100%100%
   AssetBytesParser.js100%100%100%100%
   AssetGenerator.js100%100%100%100%
   AssetModule.js100%100%100%100%
   AssetModulesPlugin.js98.15%100%100%98.15%338, 362, 365, 495, 57, 62
   AssetParser.js100%100%100%100%
   AssetSourceGenerator.js100%100%100%100%
   AssetSourceParser.js100%100%100%100%
   RawDataUrlModule.js100%100%100%100%
   WebManifestGenerator.js100%100%100%100%
   WebManifestParser.js100%100%100%100%
lib/async-modules
   AsyncModuleHelpers.js100%100%100%100%
   AwaitDependenciesInitFragment.js100%100%100%100%
   InferAsyncModulesPlugin.js100%100%100%100%
   isGeneratorLowered.js100%100%100%100%
lib/bun
   BunTargetPlugin.js100%100%100%100%
lib/cache
   AddBuildDependenciesPlugin.js100%100%100%100%
   AddManagedPathsPlugin.js100%100%100%100%
   IdleFileCachePlugin.js97.92%100%100%97.92%75, 87, 95
   MemoryCachePlugin.js92%100%100%92%33, 42
   MemoryWithGcCachePlugin.js93.42%100%100%93.42%107, 121–122, 131, 89
   PackFileCacheStrategy.js96.52%100%100%96.52%1317, 1417, 1421, 1483, 1719, 1803, 1826, 1858, 682, 701,

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.09%. Comparing base (9f6a084) to head (d89e7eb).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21907      +/-   ##
==========================================
+ Coverage   95.08%   95.09%   +0.01%     
==========================================
  Files         702      703       +1     
  Lines       90697    90739      +42     
  Branches    27368    27388      +20     
==========================================
+ Hits        86242    86292      +50     
+ Misses       4455     4447       -8     
Flag Coverage Δ
css-parsing 24.78% <0.00%> (-0.02%) ⬇️
html5lib 29.88% <0.00%> (-0.05%) ⬇️
integration 88.63% <100.00%> (+<0.01%) ⬆️
syntax-equivalence 79.75% <ø> (-0.03%) ⬇️
test262 44.54% <0.00%> (+0.04%) ⬆️
unit 56.77% <0.00%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Generated code size

Comparing d89e7eb merged into 5e6c4d7 against 5e6c4d7. Merging this pull request changes the size of 1 asset(s) and adds 2 new asset(s).

Changed New Deleted Unchanged Gzip change Raw change Gzip new/gone Raw new/gone
Cases 1 0 0 1977 🔴 ↑ +2.57 KiB 🔴 ↑ +9.59 KiB
Assets 1 2 0 7286 🔴 ↑ +1.74 KiB 🔴 ↑ +7.71 KiB +855 B +1.88 KiB
Runtimes 1 0 0 2281

Gzip change decides — it is what a user downloads, and a re-encoding can cut raw bytes while costing wire bytes. Raw change is the tiebreak: it is what the generator wrote, so it is what has to be decompressed and parsed. Both are over assets both runs emit; bytes an added or deleted case brings with it are counted apart, under new/gone. Brotli and zstd are per asset in the table below.

1 asset(s) changed size
Asset Before After Change Gzip (9) Brotli (11) Zstd (19)
🔴 ↑ concatenate-modules/commonjs-require-call-sites bundle0.js 8.53 KiB 16.24 KiB +7.71 KiB (+90.35%) +1.74 KiB (+76.28%) +1.50 KiB (+75.59%) +1.65 KiB (+73.69%)
2 asset(s) this pull request adds
Asset Raw Gzip (9) Brotli (11) Zstd (19)
concatenate-modules/commonjs-require-call-sites ensure.bundle0.js 1.24 KiB 506 B 418 B 513 B
concatenate-modules/commonjs-require-call-sites amd-target_js.bundle0.js 657 B 349 B 281 B 353 B
1 runtime(s) changed which runtime modules they carry
Runtime Modules Added Removed
🔴 ↑ concatenate-modules/commonjs-require-call-sites main 1 → 7 define property getters, ensure chunk, get javascript chunk filename, hasOwnProperty shorthand, make namespace object, readFile chunk loading

Built test/configCases with the defaults a user gets: 1978 case(s), 7289 asset(s), 76 emitted nothing.

@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 53c3353c-15e4-408a-9004-7311f376e908

📥 Commits

Reviewing files that changed from the base of the PR and between 5e6c4d7 and d89e7eb.

⛔ Files ignored due to path filters (1)
  • types.d.ts is excluded by !types.d.ts
📒 Files selected for processing (8)
  • .changeset/015-concat-require-async-callback.md
  • lib/ConcatenationScope.js
  • lib/dependencies/CommonJsRequireDependency.js
  • lib/dependencies/RequireHeaderDependency.js
  • test/configCases/concatenate-modules/commonjs-require-call-sites/amd-target.js
  • test/configCases/concatenate-modules/commonjs-require-call-sites/ensure-target.js
  • test/configCases/concatenate-modules/commonjs-require-call-sites/imported-branch.js
  • test/configCases/concatenate-modules/commonjs-require-call-sites/index.js
💤 Files with no reviewable changes (1)
  • lib/ConcatenationScope.js

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Changes

CommonJS require concatenation

Layer / File(s) Summary
Concatenated reference rendering
lib/ConcatenationScope.js, lib/dependencies/CommonJsRequireDependency.js
Removes replaced-range tracking and centralizes concatenated reference detection in CommonJsRequireDependency.
Require header replacement gating
lib/dependencies/RequireHeaderDependency.js
Skips replacement for active targets that render as concatenated references and preserves inactive-target guard handling.
Computed and asynchronous call-site coverage
test/configCases/concatenate-modules/commonjs-require-call-sites/*, .changeset/015-concat-require-async-callback.md
Adds computed require, require.ensure, and AMD callback coverage, plus a patch release changeset.

Suggested labels: regression

Merge Risk: ⚪ Minimal · up to d89e7

This PR fixes concatenated CommonJS require handling in asynchronous callbacks and computed targets with accompanying tests; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title uses the required Conventional Commit form with the allowed type fix and clearly describes the change. The branch prefix is not provided, so the required type-to-branch-prefix match cannot… Provide the branch name or confirm that its prefix is fix. Rename the title or branch if the prefixes do not match.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The changes directly address issue #21903. The dependency rendering refactor prevents unsubstituted module-reference placeholders in concatenated require() calls, and the added fixtures test `requir…
Out of Scope Changes check ✅ Passed The code changes, release changeset, and test fixtures are all related to fixing the concatenated require() regression described in issue #21903. No unrelated changes are evident.
Full details: Title check

Explanation

The title uses the required Conventional Commit form with the allowed type fix and clearly describes the change. The branch prefix is not provided, so the required type-to-branch-prefix match cannot be verified.

Full details: Linked Issues check

Explanation

The changes directly address issue #21903. The dependency rendering refactor prevents unsubstituted module-reference placeholders in concatenated require() calls, and the added fixtures test require.ensure, AMD callbacks, computed requests, and ESM whole-module access.

  • Fix all pre-merge checks with AI

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.

@coderabbitai coderabbitai Bot added the regression Worked in a previous release; pair with the Affected version field label Sep 1, 2026
@codspeed-hq

codspeed-hq Bot commented Sep 1, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 43.11%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 326 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory benchmark "wasm-modules-sync", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 349.9 KB 210.3 KB +66.34%
Memory benchmark "future-defaults", scenario '{"name":"mode-production","mode":"production"}' 10.7 MB 8.7 MB +23.12%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/concat-require-header-in-async-block (d89e7eb) with main (c50713c)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (5e6c4d7) during the generation of this report, so c50713c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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

Labels

area: parser JavaScript parsing and dependency analysis (lib/javascript, lib/dependencies) area: types types.d.ts, JSDoc annotations, hand-maintained declarations regression Worked in a previous release; pair with the Affected version field

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsubstituted __WEBPACK_MODULE_REFERENCE__ placeholder emitted into production output (regression in 5.110.0)

2 participants

Sponsor
SponsoredKunjungi sekarang
Promo