angular / angular/angular-cli

incorrect detection of zoneless app

未關閉
#30,689 10 則留言 4 個 reaction 已指派 0 人 在 GitHub 檢視
angular/build:application area: @angular/build freq1: low severity3: broken type: bug/fix
主要語言
TypeScript
星號
27k
分支
11.8k
平均合併
14 小時 23 分鐘
30 天內合併 PR
162

描述

### 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

Including any js/ts file in the polyfills array causes the angular server to incorrectly identify the app as a non-zoneless app. Thus it tries to include zone.js, which is deleted, because I uninstall the package as per the guide.

### Minimal Reproduction

-

### Exception or Error

```text

```

### Your Environment

```text
Angular CLI: 20.1.0
Node: 22.14.0
Package Manager: pnpm 10.13.1
OS: linux x64

Angular: 20.1.0
... animations, build, cdk, cli, common, compiler, compiler-cli
... core, forms, language-service, material
... material-luxon-adapter, platform-browser
... platform-browser-dynamic, platform-server, router, ssr

Package Version
---------------------------------------------------------
@angular-devkit/architect 0.2001.0
@angular-devkit/build-angular 20.1.0
@angular-devkit/core 20.1.0
@angular-devkit/schematics 20.1.0
@schematics/angular 20.0.6
ng-packagr 20.0.1
rxjs 7.8.1
typescript 5.8.3
```

### Anything else relevant?

##### TLDR

This is essentially a re-open of #28898. Developers are forced to avoid adding any js/ts file to the polyfills array. Instead, they have to create js scripts inline inside index.html, or write js files, and include them as assets with index.html

---

The problem is within these lines:
https://github.com/angular/angular-cli/blob/2c3a46b9ecf69049fbddb2c912636d9d62e197df/packages/angular/build/src/tools/esbuild/utils.ts#L469-L478

The presence of *any* js/ts file in the polyfills array causes zone to be included, even though I uninstalled zone.js and do everything zone-less-ly.

I had a file called `polyfill-buffer.ts` which I used to add to the polyfill array:
```ts
import { Buffer } from 'buffer';

if (!globalThis.Buffer) {
Object.assign(globalThis, { Buffer });
}
```

Now I have to add it to index.html as a script
```js
import { Buffer } from 'https://cdn.jsdelivr.net/npm/buffer/+esm';

if (!globalThis.Buffer) {
Object.assign(globalThis, { Buffer });
}
```

This is maintainable for small scripts like these. But it eliminates the possibility of using any file-based polyfill stuff.

貢獻指南

開啟貢獻指南

研究方向

從 packages/angular/build/src/tools/esbuild/utils.ts 的第 469-478 行開始,然後在 zone.js 無法使用的情況下,使用 polyfills 陣列中的 JavaScript 或 TypeScript 檔案執行 build 命令。完成的標準是:zoneless 應用程式不會被錯誤地偵測為 non-zoneless,且基於檔案的 polyfill 仍然正常運作。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
angular, typescript
領域
build-system, cli
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。