Skip to content

fix(esm-library): name split runtime chunk to avoid cross-lib filename collision#14508

Draft
stormslowly wants to merge 2 commits into
mainfrom
worktree-linux_flaky_24
Draft

fix(esm-library): name split runtime chunk to avoid cross-lib filename collision#14508
stormslowly wants to merge 2 commits into
mainfrom
worktree-linux_flaky_24

Conversation

@stormslowly

@stormslowly stormslowly commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Why

CI flakily fails on Linux with nearly every test crashing on the self-built @rspack/core:

packages/rspack/dist/index.js
__webpack_require__.add({  →  TypeError: __webpack_require__.add is not a function

rslib builds @rspack/core as several libraries into one shared dist/. The esm-library (optimize_runtime_chunks) splits each lib's runtime into a separate chunk but leaves it unnamed, so its filename falls back to the numeric chunk id. The index lib and the worker lib both produce dist/612.js — with different content (only index's defines __webpack_require__.add). The libs build concurrently, so the two writes to dist/612.js race; when worker's wins, index.js imports a runtime without .add and everything importing @rspack/core crashes.

webpack names its runtime chunk runtime~<entry> (unique per entry); the esm-library's split just forgot to name it.

Example failing job: https://github.com/web-infra-dev/rspack/actions/runs/27828246494/job/82359330267

What

Name the split runtime chunk after its entrypoint so it can't collide across libs sharing a directory.

two modern-module libs → one dist/ index runtime worker runtime
before 612.js 612.js ← collide
after index_runtime.js worker_runtime.js

Test: configCases/library/modern-module-runtime-chunk-naming — two libs sharing a dir both emitted 612.js before, now emit a_runtime.js / b_runtime.js (red without the fix, green with it).

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing aa445cb to chore(deps): update dependency webpack-sources to v3.5.0 (#14513) by renovate[bot]

🙈 Size remains the same at 67.93MB

@codspeed-hq

codspeed-hq Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 41 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing worktree-linux_flaky_24 (aa445cb) with main (1a36373)2

Open in CodSpeed

Footnotes

  1. 47 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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

@stormslowly stormslowly force-pushed the worktree-linux_flaky_24 branch from 5ad4380 to fca9550 Compare June 19, 2026 19:45
@stormslowly stormslowly changed the title test(esm-library): reproduce flaky __webpack_require__.add crash test(esm-library): reproduce flaky 612.js chunk collision crash Jun 19, 2026
@stormslowly stormslowly force-pushed the worktree-linux_flaky_24 branch from fca9550 to bbaf95a Compare June 20, 2026 06:17
@stormslowly stormslowly changed the title test(esm-library): reproduce flaky 612.js chunk collision crash fix(esm-library): name split runtime chunk to avoid cross-lib filename collision Jun 20, 2026
@stormslowly stormslowly force-pushed the worktree-linux_flaky_24 branch from bbaf95a to baf2b89 Compare June 20, 2026 06:23
…e collision

When the esm-library splits the runtime into a separate chunk
(optimize_runtime_chunks), it only added an id name hint and left the chunk
unnamed, so its filename fell back to the numeric chunk id (e.g. 612.js).

Two compilations that share one output directory - e.g. multiple rslib libs
built into the same dist/ - can each independently produce a runtime chunk
with the same id and the same filename. Because the libs build concurrently the
writes race, so the entry that imports './612.js' may get the other lib's
runtime, which lacks its __webpack_require__.add registration helper and crashes
with 'TypeError: __webpack_require__.add is not a function'.

Name the runtime chunk after its entrypoint (mirroring webpack's
optimization.runtimeChunk 'runtime~<entry>' convention) so it is unique per
entry and cannot collide across libraries.

A configCase reproduces the collision: two modern-module libs (runtimeChunk
disabled so the esm-library splits the runtime itself) sharing one output dir
previously both emitted '612.js'; now they emit 'a_runtime.js' and
'b_runtime.js'.
@stormslowly stormslowly force-pushed the worktree-linux_flaky_24 branch from baf2b89 to db15c29 Compare June 20, 2026 08:28
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 20, 2026

Copy link
Copy Markdown

Deploying rspack with  Cloudflare Pages  Cloudflare Pages

Latest commit: aa445cb
Status: ✅  Deploy successful!
Preview URL: https://5de25aef.rspack-v2.pages.dev
Branch Preview URL: https://worktree-linux-flaky-24.rspack-v2.pages.dev

View logs

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.

1 participant