Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Chunk optimizer drops a chunk shared between the main bundle and a web worker

オープン
#34,292 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript

調査の方向性

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 の本文から書いたものです。

説明

area: @angular/build
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

  1. pnpm install
  2. pnpm exec ng build
  3. sh check-missing-chunks.sh. This lists every ./chunk-*.js import in dist/**/browser that has no matching file.

Output:

MISSING: chunk-46XWIMCN.js imports chunk-I4HABNO6.js
MISSING: chunk-HAJXH3QZ.js imports chunk-I4HABNO6.js
  1. NG_BUILD_OPTIMIZE_CHUNKS=false pnpm exec ng build followed by sh check-missing-chunks.sh reports 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日 1時間
マージ済み PR(30日)
161

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

angular/angular-cli のほかの issue

angular/angular-cli の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。