Skip to content

fix(wasm): resolve binaries from nested runtime chunks - #22916

Merged
alexander-akait merged 1 commit into
mainfrom
fix/wasm-nested-runtime-path
Oct 26, 2026
Merged

alexander-akait merged 1 commit into
mainfrom
fix/wasm-nested-runtime-path

Conversation

@bjohansebas

@bjohansebas bjohansebas commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Async WebAssembly fails when its runtime is emitted in a subdirectory: fallback filenames resolve next to the JavaScript instead of the output root. This affects universal and async-node loading, including workers and source-phase imports.

For example:

{
  target: "universal",
  devtool: "eval",
  experiments: { asyncWebAssembly: true },
  output: {
    filename: "nested/deep/main.mjs",
    webassemblyModuleFilename: "wasm/[hash].wasm"
  }
}

The emitted path changes from:

// Before: looks in nested/deep/wasm/ and fails
var wasmUrl = "wasm/" + wasmModuleHash + ".wasm";

// After: finds the binary in wasm/
var wasmUrl = "../../wasm/" + wasmModuleHash + ".wasm";

Compute the prefix during code generation and fold it into the existing literal, adding no runtime operations. CommonJS async-node also needs this without eval. Complete URLs and fetch loading through publicPath keep their existing behavior.

Targeted yarn test:size: affected bundles gain 2–6 bytes gzip (+12 raw bytes each); 79 assets are unchanged. No runtime modules are added.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes: test/configCases/wasm/nested-runtime/ and nested-worker-runtime/. The first reproduces eight failures on main. All 196 targeted tests pass across ConfigTestCases and ConfigCacheTestCases, all changed executable lines are covered, and full lint passes.

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

Codex assisted with reproducing the bug, implementing the fix, writing and running regression tests, and drafting this description.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed asynchronous WebAssembly loading when runtime chunks are emitted in nested directories.
    • Nested WebAssembly paths now work across supported output formats and in workers.

@changeset-bot

changeset-bot Bot commented Oct 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0516f0a

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: wasm WebAssembly modules (lib/wasm-*) area: runtime Emitted runtime and chunk loading across targets (lib/runtime, lib/web, lib/node, lib/esm) labels Oct 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview of its latest commit is available.

Install it locally:

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

@github-actions

Copy link
Copy Markdown
Contributor

Types Coverage

Coverage after merging fix/wasm-nested-runtime-path into main will be
99.29%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
bin
   webpack.js98.84%100%100%98.84%113
declarations
   WebpackOptions.ts99.94%100%100%99.94%4240
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/ssr
   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
   Chunk.js100%100%100%100%
   Compilation.js98.74%100%100%98.74%1823, 2135, 2142, 2150, 2172, 2175, 3161, 3720, 3763, 4358, 4362, 4488, 4509, 4634, 4671, 4678, 4731–4732, 4736, 4741, 4757–4758, 4772–4773, 4778–4779, 5307, 5333, 6254, 6271, 6289, 6305, 6320, 6345, 6348, 6760, 6763–6764, 6769, 6784, 6867, 6891, 883–884
   Compiler.js98.81%100%100%98.81%1107, 1144, 1147, 1323–1324, 1332, 848, 932, 972
   Dependency.js100%100%100%100%
   DependencyTemplate.js100%100%100%100%
   EntryPlugin.js100%100%100%100%
   Entrypoint.js100%100%100%100%
   ExternalsPlugin.js100%100%100%100%
   FileSystemInfo.js100%100%100%100%
   InitFragment.js100%100%100%100%
   LibraryTemplatePlugin.js100%100%100%100%
   ModuleFilenameHelpers.js100%100%100%100%
   ModuleNotFoundError.js100%100%100%100%
   MultiCompiler.js98.91%100%100%98.91%489, 561, 748, 813
   NormalModule.js100%100%100%100%
   NullFactory.js100%100%100%100%
   ProgressPlugin.js100%100%100%100%
   RawModule.js100%100%100%100%
   RequestShortener.js100%100%100%100%
   SingleEntryPlugin.js100%100%100%100%
   WebpackError.js100%100%100%100%
   index.js100%100%100%100%
   webpack.js98.59%100%100%98.59%306, 308
lib/asset
   AssetBytesGenerator.js100%100%100%100%
   AssetBytesParser.js91.67%100%100%91.67%27
   AssetGenerator.js100%100%100%100%
   AssetModule.js100%100%100%100%
   AssetModulesPlugin.js98.45%100%100%98.45%334, 360, 363, 493, 58
   AssetParser.js96.15%100%100%96.15%47
   AssetSourceGenerator.js100%100%100%100%
   AssetSourceParser.js91.67%100%100%91.67%27
   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%
   Cache.js98.25%100%100%98.25%104
   CacheFacade.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%106, 120–121, 130, 88
   PackFileCacheStrategy.js96.54%100%100%96.54%1304, 1404, 1408, 1470, 1716, 1796, 1819, 1849, 684, 703, 713–715, 717, 733–734, 739, 742, 744, 749, 754, 779, 785, 819, 825, 831, 836, 847, 856, 861–862, 864, 881, 887–888, 890
   ResolverCachePlugin.js100%100%100%100%
   getLazyHashedEtag.js100%100%100%100%
   mergeEtags.js100%100%100%100%
lib/config
   OptionsApply.js100%100%100%100%
   PlatformPlugin.js100%100%100%100%
   WebpackOptionsApply.js100%100%100%100%
   WebpackOptionsDefaulter.js100%100%100%100%
   browserslistTargetHandler.js100%100%100%100%
   cli.js98.89%100%100%98.89%114, 549, 581, 631
   defaults.js99.59%100%100%99.59%1633–1635, 1643, 288, 548
   defineConfig.js100%100%100%100%
   getClaimedAssetTypes.js100%100%100%100%
   normalization.js99.14%100%100%99.14%285–286, 356, 371
   target.js100%100%100%100%
   validateSchema.js94.67%100%100%94.67%100, 87, 89, 98
lib/container
   ContainerEntryDependency.js100%100%100%100%
   ContainerEntryModule.js100%100%100%100%
   ContainerEntryModuleFactory.js100%100%100%100%
   ContainerExposedDependency.js100%100%100%100%
   ContainerPlugin.js100%100%100%100%
   ContainerReferencePlugin.js100%100%100%100%
   FallbackDependency.js100%100%100%100%
   FallbackItemDependency.js100%100%100%100%
   FallbackModule.js100%100%100%100%
   FallbackModuleFactory.js100%100%100%100%
   HoistContainerReferencesPlugin.js100%100%100%100%
   ModuleFederationPlugin.js100%100%100%100%
   RemoteModule.js100%100%100%100%
   RemoteRuntimeModule.js100%100%100%100%
   RemoteToExternalDependency.js100%100%100%100%
   declaredRemotes.js100%100%100%100%
   moduleFederationHooks.js100%100%100%100%
   options.js100%100%100%100%
lib/context
   ContextExclusionPlugin.js100%100%100%100%
   ContextModule.js99.88%100%100%99.88%1495
   ContextModuleFactory.js95.70%100%100%95.70%230, 257, 276, 280–281, 289, 466, 487, 492, 534, 543, 545, 549, 552, 558–559
   ContextReplacementPlugin.js100%100%100%100%
lib/css
   CssGenerator.js99.29%100%100%99.29%1085, 129, 305, 837
   CssInjectStyleRuntimeModule.js100%100%100%100%
   CssLoadingRuntimeModule.js100%100%100%100%
   CssModule.js100%100%100%100%
   CssModulesPlugin.js98.72%100%100%98.72%217, 418, 432, 445, 458, 481, 494, 507, 520
   CssParser.js99.76%100%100%99.76%1089, 2424, 3071, 3074, 3080, 3512, 942
   CssServerStylesRuntimeModule.js100%100%100%100%
   conventions.js100%100%100%100%
   cssMinify.js100%100%100%100%
   data.js99.84%100%100%99.84%229, 5605
   syntax-parser.js99.70%100%100%99.70%10975–10976, 11528–11529, 11566, 11776, 11825, 14220, 14281–14284, 14389–14390, 14488–14489, 15262, 15558, 15560, 16115, 16507, 16549, 18939, 3066, 3068, 3073, 3086, 3837, 3843
   syntax-printer.js99.33%100%100%99.33%2611–2612, 2614–2615, 2617–2618, 2623, 2893–2896, 2989, 356, 3690, 4115, 4251, 4928, 5242, 6143, 730
   syntax.js100%100%100%100%
   topologicalSort.js100%100%100%100%
lib/debug
   ProfilingPlugin.js100%100%100%100%
lib/define
   DefinePlugin.js99.42%100%100%99.42%1488, 936, 938, 943, 967
   DotenvPlugin.js97.61%100%100%97.61%276, 395, 443, 456–457
   EnvironmentPlugin.js100%100%100%100%
lib/deno
   DenoTargetPlugin.js100%100%100%100%
lib/dependencies
   ConstDependency.js100%100%100%100%
   ContextElementDependency.js100%100%100%100%
   NullDependency.js100%100%100%100%
lib/dependencies/amd
   AMDDefineDependency.js100%100%100%100%
   AMDDefineDependencyParserPlugin.js100%100%100%100%
   AMDPlugin.js99.31%100%100%99.31%54
   AMDRequireArrayDependency.js100%100%100%100%
   AMDRequireContextDependency.js100%100%100%100%
   AMDRequireDependenciesBlock.js100%100%100%100%
   AMDRequireDependenciesBlockParserPlugin.js100%100%100%100%
   AMDRequireDependency.js100%100%100%100%
   AMDRequireItemDependency.js100%100%100%100%
   AMDRuntimeModules.js95.45%100%100%95.45%65
   LocalModule.js100%100%100%100%
   LocalModuleDependency.js100%100%100%100%
   LocalModulesHelpers.js100%100%100%100%
   RequireJsStuffPlugin.js100%100%100%100%
   UnsupportedDependency.js100%100%100%100%
lib/dependencies/commonjs
   CommonJsDependencyHelpers.js98.63%100%100%98.63%43
   CommonJsExportRequireDependency.js99.21%100%100%99.21%413, 415, 417
   

@github-actions

Copy link
Copy Markdown
Contributor

Generated code size

Comparing base (669012d) to head (0516f0a). Merging this pull request adds 12 new asset(s).

What moved Tests Assets Gzip Raw Test edit
Changed, test untouched 0 0 — — —
Changed, test edited 0 0 — — —
New 2 12 ⚪ added +8.88 KiB ⚪ added +21.73 KiB —
Deleted 0 0 — — —
Unchanged — 9200 — — —

Read Changed, test untouched first: the test is byte-identical on both sides, so webpack generated the difference. Changed, test edited moved partly because the test did — Test edit is how many bytes the test gained, and a bundle that grew by less is not a regression. New and Deleted are whole files, not deltas — a new asset was created, not grown, so it reads gray (⚪ added) — and adding tests cannot bury a real change. Gzip decides, because that is what users download; raw is the tiebreak, and brotli and zstd are per asset below.

No asset that both runs emit changed size — everything below is new or deleted.

12 asset(s) this pull request adds
Asset Raw Gzip (9) Brotli (11) Zstd (19)
⚪ added wasm/nested-worker-runtime workers/nested/447.mjs 5.35 KiB 1.93 KiB 1.72 KiB 1.90 KiB
⚪ added wasm/nested-runtime 0/nested/deep/main.0.mjs 4.29 KiB 1.55 KiB 1.37 KiB 1.54 KiB
⚪ added wasm/nested-runtime 3/nested/deep/main.3.mjs 3.81 KiB 1.42 KiB 1.26 KiB 1.41 KiB
⚪ added wasm/nested-runtime 1/nested/deep/main.1.mjs 3.35 KiB 1.29 KiB 1.17 KiB 1.28 KiB
⚪ added wasm/nested-runtime 2/nested/deep/main.2.js 2.36 KiB 1.08 KiB 1003 B 1.07 KiB
⚪ added wasm/nested-worker-runtime entry/main.mjs 1.62 KiB 747 B 642 B 759 B
⚪ added wasm/nested-worker-runtime entry/788.main.mjs 570 B 305 B 265 B 301 B
⚪ added wasm/nested-runtime 3/wasm/[hash].wasm 78 B 118 B 86 B 96 B
⚪ added wasm/nested-runtime 0/wasm/[hash].wasm 78 B 118 B 86 B 96 B
⚪ added wasm/nested-runtime 1/wasm/[hash].wasm 78 B 118 B 86 B 96 B
⚪ added wasm/nested-runtime 2/wasm/[hash].wasm 78 B 118 B 86 B 96 B
⚪ added wasm/nested-worker-runtime wasm/[hash].wasm 78 B 118 B 86 B 96 B

No runtime that both runs build changed which runtime modules it carries.

6 runtime(s) this pull request adds or no longer builds
Runtime Modules
➕ wasm/nested-worker-runtime [hash] 7
➕ wasm/nested-runtime 0/main 5
➕ wasm/nested-runtime 1/main 5
➕ wasm/nested-runtime 2/main 5
➕ wasm/nested-runtime 3/main 5
➕ wasm/nested-worker-runtime main 4

Built test/configCases with the defaults a user gets: 2292 test(s), 9212 asset(s), 101 emitted nothing.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 669012d and 0516f0a.

Files selected for processing: 15
  • .changeset/043-wasm-nested-runtime-path.md
  • lib/node/ReadFileCompileAsyncWasmPlugin.js
  • lib/wasm/AsyncWasmCompileRuntimeModule.js
  • lib/wasm/AsyncWasmLoadingRuntimeModule.js
  • lib/wasm/UniversalCompileAsyncWasmPlugin.js
  • test/configCases/wasm/nested-runtime/index.js
  • test/configCases/wasm/nested-runtime/test.config.js
  • test/configCases/wasm/nested-runtime/test.filter.js
  • test/configCases/wasm/nested-runtime/wasm.wat
  • test/configCases/wasm/nested-runtime/webpack.config.js
  • test/configCases/wasm/nested-worker-runtime/index.js
  • test/configCases/wasm/nested-worker-runtime/test.config.js
  • test/configCases/wasm/nested-worker-runtime/test.filter.js
  • test/configCases/wasm/nested-worker-runtime/webpack.config.js
  • test/configCases/wasm/nested-worker-runtime/worker.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

Async WebAssembly runtime modules can resolve binary paths relative to the runtime chunk’s output directory. Node and universal plugins enable this option. New config cases cover nested runtime output and WebAssembly loaded from a nested worker.

Changes: Nested WebAssembly runtime paths

Layer / File(s) Summary
Runtime path generation
lib/wasm/AsyncWasmCompileRuntimeModule.js, lib/wasm/AsyncWasmLoadingRuntimeModule.js
Both runtime modules add the optional useRelativePath option, defaulting to false. When enabled, each prefixes the configured WebAssembly filename with the runtime chunk’s relative output directory.
Plugin configuration
lib/node/ReadFileCompileAsyncWasmPlugin.js, lib/wasm/UniversalCompileAsyncWasmPlugin.js, .changeset/043-wasm-nested-runtime-path.md
The Node and universal plugins enable useRelativePath for both runtime modules. The changeset describes the nested-output path fix.
Nested output tests
test/configCases/wasm/nested-runtime/*, test/configCases/wasm/nested-worker-runtime/*
Config cases test eager WebAssembly imports with nested runtime output and WebAssembly loading from a nested worker. The cases include runtime-specific filters and bundle configuration.

Suggested labels: area: wasm

Suggested reviewers: magic-akari, alexander-akait

Priority: Normal

Change: Bug fix

Merge Risk: Minimal · up to 0516f

The nested runtime paths point to the emitted WebAssembly assets. No actionable issue remains before merge.

Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title follows the conventional-commit form fix(wasm): subject. The type fix and the scope wasm are valid. The subject "resolve binaries from nested runtime chunks" matches the main change. T…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title follows the conventional-commit form fix(wasm): subject. The type fix and the scope wasm are valid. The subject "resolve binaries from nested runtime chunks" matches the main change. The changeset fixes Async WebAssembly loading when the runtime chunk is emitted in a subdirectory, and the PR objectives state the same title. The title does not state a branch prefix, so the branch-match part of the requirement cannot be verified from the provided context.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codspeed

codspeed Bot commented Oct 25, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 9.23%

2 warnings, 1 note

⚠️ 117 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

ℹ️ 46 benchmarks have no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 349 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory benchmark "many-modules-commonjs", scenario '{"name":"mode-production","mode":"production"}' 995.9 KB 1,495.1 KB -33.39%
⚡ Memory benchmark "common-libs", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 189 KB 152.8 KB +23.67%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/wasm-nested-runtime-path (0516f0a) with main (669012d)

Open in CodSpeed

@alexander-akait
alexander-akait merged commit cd540bd into main Oct 26, 2026
70 checks passed
@alexander-akait
alexander-akait deleted the fix/wasm-nested-runtime-path branch October 26, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Emitted runtime and chunk loading across targets (lib/runtime, lib/web, lib/node, lib/esm) area: wasm WebAssembly modules (lib/wasm-*)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants