Chunk optimizer drops a chunk shared between the main bundle and a web worker
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- build-system, frontend
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 27k
- Fork
- 11.8k
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 156
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của angular/angular-cli
-
area: @angular/cli
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
angular/angular-cli#34307 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-serverĐang mởarea: @angular/build gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
angular/angular-cli#33955 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: @angular/cli gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
angular/angular-cli#33055 · 1 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
@angular/ssr: page under nested empty-path routes is prerendered without the modulepreload hints of its lazy chunks (regression since 19.1.6)Có thể đã có người làm @alan-agius4 đã nhận hôm nay. Đang mởarea: @angular/ssr
angular/angular-cli#34320 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: @angular/build
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
angular/angular-cli#34312 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của angular/angular-cli
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
area:cowork area:desktop documentation enhancement platform:macos
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
anthropics/claude-code#101720 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
apache/rocketmq-dashboard#6610 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Add: MS NOWĐang mởcheck:passed streams:add
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Global update drops overrideAccess, so Local API updateGlobal fails filterOptions validation (3.90 regression)Có thể đã có người làm @PINYOPATTANAWASANPORN đã nhận hôm nay. Đang mởarea: core Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
payloadcms/payload#18674 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày