Title: `NG_BUILD_OPTIMIZE_CHUNKS` can cause variable name collisions · Issue #32764 · angular/angular-cli · GitHub
Open Graph Title: `NG_BUILD_OPTIMIZE_CHUNKS` can cause variable name collisions · Issue #32764 · angular/angular-cli
X Title: `NG_BUILD_OPTIMIZE_CHUNKS` can cause variable name collisions · Issue #32764 · angular/angular-cli
Description: 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 Yes NG_BUILD_OPTIMIZE_CHUNKS is still experimental. This is ju...
Open Graph Description: 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 Yes NG_BUILD_OPTIMIZE_...
X Description: 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 Yes NG_BUILD_OPTIMIZE_...
Opengraph URL: https://github.com/angular/angular-cli/issues/32764
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`NG_BUILD_OPTIMIZE_CHUNKS` can cause variable name collisions","articleBody":"### Command\n\nbuild\n\n### Is this a regression?\n\n- [ ] Yes, this behavior used to work in the previous version\n\n### The previous version in which this bug was not present was\n\n_No response_\n\n### Description\n\nYes `NG_BUILD_OPTIMIZE_CHUNKS` is still experimental. This is just a bug I came across while testing it for #27715. I hit a rather nasty edge case with it on where two variable names ended up colliding inside main.js, one from a core Angular package, and the other being one of my components. Thankfully it broke the runtime early on cause otherwise I never would've caught it.\n\nThe mangled variable name that got hit was `Wb`. The first occurrence appears to be from https://github.com/angular/angular/blob/17d8a88ddcce3f850b8ab72252e05720e1f3a8be/packages/core/src/render3/definition.ts#L398-L436\n```js\nfunction Wb(e){return ro$3(()=\u003e({type:e.type,bootstrap:e.bootstrap||ce$4,declarations:e.declarations||ce$4,imports:e.imports||ce$4,exports:e.exports||ce$4,transitiveCompileScopes:null,schemas:e.schemas||null,id:e.id||null}))}\n```\nThe second occurrence comes from one of my components (snippet under reproduction)\n```js\nvar Wb=[`open`,`opening`,`toggle`],Fi=class o{constructor(e,t){this._document=e;this._elementRef=t;let r=Wb.map(i=\u003e$U(ea(this._document,i,{capture:!0,passive:!0}).pipe(Pe$11(s=\u003es.target instanceof Element\u0026\u0026s.target!==this._elementRef.nativeElement\u0026\u0026!s.target.tagName.toLowerCase().startsWith(`md-menu`)))));\n```\n`Wb` breaks upon calling it on the third occurrence \u003cins\u003ein the same line as the previous\u003c/ins\u003e (which I assume means the same chunk), which appears to be from https://github.com/angular/components/blob/main/src/cdk-experimental/scrolling/scrolling-module.ts\n```js\nstatic ɵdir=Qb({type:o,selectors:[[`cdk-virtual-scroll-viewport`,`autosize`,``]],inputs:{minBufferPx:`minBufferPx`,maxBufferPx:`maxBufferPx`},features:[mw([{provide:bi$1,useFactory:D_,deps:[ci$5(()=\u003eo)]}]),TI]})}return o})(),Jh=(()=\u003e{class o{static ɵfac=function(r){return new(r||o)};static ɵmod=Wb({type:o});\n```\n\n### Minimal Reproduction\n\nThe mangled names appear to follow a deterministic sequence so you just have to hit it with enough variable declarations and some luck. Best I can offer is the component that got hit:\n```ts\nimport {\n ChangeDetectionStrategy,\n Component,\n DOCUMENT,\n ElementRef,\n Inject,\n} from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { filter, fromEvent } from 'rxjs';\n\nconst POPOVER_EVENTS = ['open', 'opening', 'toggle'];\n\n@Component({\n selector: 'md-menu',\n styleUrl: './menu.component.scss',\n templateUrl: './menu.component.html',\n})\nexport class MenuComponent {\n constructor(\n @Inject(DOCUMENT) private readonly _document: Document,\n private readonly _elementRef: ElementRef\u003cHTMLElement\u003e,\n ) {\n const signals = POPOVER_EVENTS.map((name) =\u003e\n toSignal(\n fromEvent(this._document, name, { capture: true, passive: true }).pipe(\n filter(\n (value) =\u003e\n value.target instanceof Element \u0026\u0026\n value.target !== this._elementRef.nativeElement \u0026\u0026\n !value.target.tagName.toLowerCase().startsWith('md-menu'),\n ),\n ),\n ),\n );\n }\n}\n\n```\n\n### Exception or Error\n\n```text\nUncaught TypeError: Wb is not a function\n at \u003cstatic_initializer\u003e (main-3IQSYYTY.js:1066:5353)\n at main-3IQSYYTY.js:1066:5278\n at main-3IQSYYTY.js:1066:5399\n at main-3IQSYYTY.js:1:101\n at main-3IQSYYTY.js:1068:36238\n```\n\n### Your Environment\n\n```text\nAngular CLI : 21.2.2\nAngular : 21.1.5\nNode.js : 24.14.0\nPackage Manager : pnpm 10.32.1\nOperating System : win32 x64\n```\n\n### Anything else relevant?\n\n_No response_","author":{"url":"https://github.com/austinw-fineart","@type":"Person","name":"austinw-fineart"},"datePublished":"2026-03-13T09:42:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/32764/angular-cli/issues/32764"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bb294aaf-69ab-0ace-e71b-3dc7d928d905 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B294:1A5583:35A0EC:48285B:6A629345 |
| html-safe-nonce | 2e0e0ecd28ecfbab49e8c314bc0e79c59dd549783bc5fa2d7bffabe119b8ee6c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjk0OjFBNTU4MzozNUEwRUM6NDgyODVCOjZBNjI5MzQ1IiwidmlzaXRvcl9pZCI6IjI4MjE1NzkzNDY3MTI2MzAwODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | aea000af77cfdb8fc39c15da5366abbd521306780008b1f154dba9003945e64a |
| hovercard-subject-tag | issue:4070024531 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/32764/issue_layout |
| twitter:image | https://opengraph.githubassets.com/15c4518614598cf71e746c4e5ce1bb5f89545a3f413d5971f37b8382efe0f443/angular/angular-cli/issues/32764 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/15c4518614598cf71e746c4e5ce1bb5f89545a3f413d5971f37b8382efe0f443/angular/angular-cli/issues/32764 |
| og:image:alt | 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 Yes NG_BUILD_OPTIMIZE_... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | austinw-fineart |
| hostname | github.com |
| expected-hostname | github.com |
| None | 10ffaff7e212112a3b4eeb224665f909dff951514db9af4f00de33b681024427 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e470e2fc66e1ac7f528caec0fd8825047788d563 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width