Chunk optimizer drops a chunk shared between the main bundle and a web worker
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- typescript
- 领域
- build-system, frontend
调研方向
Start with the reproduction repo and run NG_BUILD_OPTIMIZE_CHUNKS=false against it to confirm the baseline, then look at bundleWebWorker in compiler-plugin.js and the chunk optimizer that runs over the main bundle. Done means that sh check-missing-chunks.sh reports nothing missing with the optimizer enabled, and that the worker's shared chunk still exists in dist. The issue leaves open whether to exclude worker-referenced chunks from removal or to optimize worker outputs with the main bundle, so the design choice needs a maintainer.
由索引模型根据 Issue 内容生成。
描述
Command
build
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
When a web worker and the main application dynamically import the same modules, and those modules share a dependency, the production build emits worker chunks that import a chunk that is not written to the output directory.
The worker is bundled separately (bundleWebWorker in compiler-plugin.js) with the same chunk-[hash] naming as the main bundle. Because the content is identical, the worker's shared chunk gets the same file name as a chunk of the main bundle. The chunk optimizer then rewrites the main bundle's chunks with Rolldown and the original esbuild chunk is no longer emitted. The worker chunks still reference it, so the file is missing from dist.
At runtime, the worker's dynamic import requests a chunk that returns 404 on the server.
With NG_BUILD_OPTIMIZE_CHUNKS=false every referenced chunk is emitted and the worker works.
Real-world case: a report worker that lazily loads jspdf and write-excel-file, which both depend on fflate. The fflate chunk was missing, so PDF and XLSX generation in the worker failed in production only.
Minimal Reproduction
Repository: https://github.com/jsandrea88/worker-chunk-repro
pnpm installpnpm exec ng buildsh check-missing-chunks.sh. This lists every./chunk-*.jsimport indist/**/browserthat has no matching file.
Output:
MISSING: chunk-46XWIMCN.js imports chunk-I4HABNO6.js
MISSING: chunk-HAJXH3QZ.js imports chunk-I4HABNO6.js
NG_BUILD_OPTIMIZE_CHUNKS=false pnpm exec ng buildfollowed bysh check-missing-chunks.shreports nothing missing.
Code:
// zip-a.ts
import { zipSync } from 'fflate';
export const zipA = () => zipSync({ 'a.txt': new Uint8Array([97]) });
// zip-b.ts
import { unzipSync, zipSync } from 'fflate';
export const zipB = () => unzipSync(zipSync({ 'b.txt': new Uint8Array([98]) }));
// zip.worker.ts
addEventListener('message', async () => {
const [{ zipA }, { zipB }] = await Promise.all([import('./zip-a'), import('./zip-b')]);
postMessage(`${zipA().length} ${Object.keys(zipB()).length}`);
});
// app.ts (main bundle): dynamic imports of the same modules, plus a third lazy
// chunk to reach the default optimization threshold of 3 lazy chunks
await Promise.all([import('./zip-a'), import('./zip-b'), import('./lazy-c')]);
new Worker(new URL('./zip.worker', import.meta.url), { type: 'module' });
If the worker imports fflate directly, without the two shared intermediate modules, the problem does not reproduce.
Exception or Error
No build error. The output contains chunks that import a file that does not exist (see the reproduction output). In the browser, the worker's dynamic import fails with a 404 for that chunk.
Your Environment
Angular CLI : 22.2.2
Angular : 22.2.1
Node.js : 24.18.1
Package Manager : pnpm 11.5.3
Operating System : win32 x64
@angular/build 22.2.2
@angular/cli 22.2.2
@angular/core 22.2.1
typescript 6.0.3
Anything else relevant?
Workaround: NG_BUILD_OPTIMIZE_CHUNKS=false.
Possible fixes: exclude chunks referenced by web worker outputs from the optimizer's removal, or run the optimizer over the worker outputs together with the main bundle.
Regression status: not bisected. The chunk optimizer has been enabled by default since 22.0.0 (cd2ad3c19), so I expect builds before that to be unaffected, but I have not verified it.
- 主要语言
- TypeScript
- 星标
- 27k
- 派生
- 11.8k
- 平均合并
- 1 天 32 分钟
- 30 天内合并 PR
- 138
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
angular/angular-cli 的其他 Issue
-
area: @angular/cli
难度 2/5 1-3 小时 新手友好度 78/100
angular/angular-cli#34307 ·
维护者通常 1 天内回复
-
area: @angular/build gemini-triaged
难度 2/5 1-3 小时 新手友好度 74/100
angular/angular-cli#33955 ·
维护者通常 1 天内回复
-
area: @angular/cli gemini-triaged
难度 2/5 1-3 小时 新手友好度 72/100
angular/angular-cli#33055 · 1 条评论 · 3 个 reaction ·
维护者通常 1 天内回复
-
SSR resolves relative `redirectTo` against the wrong base when the route path has several segments可能已有人在做 @bschaeublin 于 3 天前认领。 未关闭area: @angular/ssr
难度 3/5 1-2 天 新手友好度 45/100
angular/angular-cli#34300 ·
维护者通常 1 天内回复
-
SSR route redirects drop the query string on relative `redirectTo`可能已有人在做 @bschaeublin 于 3 天前认领。 未关闭area: @angular/ssr
难度 3/5 1-2 天 新手友好度 45/100
angular/angular-cli#34298 ·
维护者通常 1 天内回复
查看 angular/angular-cli 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/playwright#43327 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/TypeScript#64758 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 65/100
opensearch-project/OpenSearch-Dashboards#12937 ·
维护者通常 2 天内回复
-
Liveness marks block-included attesters live in the block's epoch instead of the attestation's epoch未关闭
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
status: needs-triage
难度 2/5 1-3 小时 新手友好度 83/100
a2ui-project/a2ui#3158 ·
维护者通常 2 天内回复