Title: unit-test builder (Vitest, 22.2.0 OXC linker): ReferenceError on class referenced by name before its own declaration in a partially-compiled npm library · Issue #34198 · angular/angular-cli · GitHub
Open Graph Title: unit-test builder (Vitest, 22.2.0 OXC linker): ReferenceError on class referenced by name before its own declaration in a partially-compiled npm library · Issue #34198 · angular/angular-cli
X Title: unit-test builder (Vitest, 22.2.0 OXC linker): ReferenceError on class referenced by name before its own declaration in a partially-compiled npm library · Issue #34198 · angular/angular-cli
Description: Command test Is this a regression? Not sure — this may be a regression introduced by the linker rewrite in 22.2.0 ("migrate Angular Linker to oxc-parser and magic-string"), since I have not tested this with 22.1.x. The previous version i...
Open Graph Description: Command test Is this a regression? Not sure — this may be a regression introduced by the linker rewrite in 22.2.0 ("migrate Angular Linker to oxc-parser and magic-string"), since I have not tested ...
X Description: Command test Is this a regression? Not sure — this may be a regression introduced by the linker rewrite in 22.2.0 ("migrate Angular Linker to oxc-parser and magic-string"), since I have n...
Opengraph URL: https://github.com/angular/angular-cli/issues/34198
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"unit-test builder (Vitest, 22.2.0 OXC linker): ReferenceError on class referenced by name before its own declaration in a partially-compiled npm library","articleBody":"### Command\n\ntest\n\n### Is this a regression?\n\nNot sure — this may be a regression introduced by the linker rewrite in 22.2.0 (\"migrate Angular Linker to oxc-parser and magic-string\"), since I have not tested this with 22.1.x.\n\n### The previous version in which this bug was not present was\n\n_No response_\n\n### Description\n\nWhen running `ng test` with the `@angular/build:unit-test` builder (Vitest runner) on Angular CLI / @angular/build 22.2.0, several test files fail to load at all (0 tests reported, whole suite crashes) with:\n\nReferenceError: Cannot access 'CascadeSelect' before initialization\nat CascadeSelectSub.\u003cstatic_initializer> node_modules/@openng/src/cascadeselect/cascadeselect.ts:131:30\n\n\nI traced this to the actual shipped file (the path above is a sourcemap reference, not a real file on disk):\n`node_modules/@openng/optimus-ui/fesm2022/openng-optimus-ui-cascadeselect.mjs`\n\nIn that file, `CascadeSelectSub` is declared at line 176, and its static Ivy partial declaration at line 274 includes:\n\n```js\nstatic ɵfac = i0.ɵɵngDeclareFactory({ ..., type: CascadeSelectSub, deps: [{ token: CascadeSelect }], target: i0.ɵɵFactoryTarget.Component });\n```\n\n`CascadeSelect` (the referenced class) is not declared until line 452, further down in the same file. Since this is emitted as a literal `class` declaration (temporal dead zone applies), referencing the identifier `CascadeSelect` before its declaration executes throws a `ReferenceError` — unless the Angular linker processes this partial-compilation output (`ɵɵngDeclareFactory`, `ɵɵngDeclareComponent`) into a fully-linked form first, which is presumably not order-sensitive.\n\nThis same package builds and tests fine under the classic Karma + `@angular-devkit/build-angular` pipeline, which suggests the linker is applied correctly there but not (or not correctly) for this specific cross-class-reference pattern under the `unit-test` builder in 22.2.0.\n\n\n\n### Minimal Reproduction\n\nI don't have an isolated reproduction yet, but you've provided the full trace and the exact line of the affected packet.\n\n### Exception or Error\n\n```text\nReferenceError: Cannot access 'CascadeSelect' before initialization\n❯ CascadeSelectSub.\u003cstatic_initializer> node_modules/@openng/src/cascadeselect/cascadeselect.ts:131:30\n❯ node_modules/@openng/src/cascadeselect/cascadeselect.ts:131:39\n\n(Note: the path shown is from the package's sourcemap; the real file evaluated is `node_modules/@openng/optimus-ui/fesm2022/openng-optimus-ui-cascadeselect.mjs`.)\n```\n\n### Your Environment\n\n```text\nAngular CLI: 22.2.0\n@angular/build: 22.2.0\nVitest: 5.0.2\nNode: v24.21.0\nOS: Windows\n```\n\n### Anything else relevant?\n\n- The affected npm package is `@openng/optimus-ui` (latest version at time of reporting).\n- The broken class is `CascadeSelect` / `CascadeSelectSub`, distributed in Ivy partial-compilation format (`ɵɵngDeclareComponent`, `ɵɵngDeclareFactory`).\n- `CascadeSelectSub` is declared earlier in the file than `CascadeSelect`, and its factory's `deps` array references `CascadeSelect` by identifier without going through `forwardRef`.\n- This surfaced right after upgrading to 22.2.0, which per the changelog migrated the Angular Linker to oxc-parser/magic-string and included several linker-related fixes in the same release (syntax corruption, parenthesized expressions, source mapping). This may be an edge case not yet covered by the new OXC-based linker implementation.\n- Affects every test file whose import graph pulls in this component (via a shared header/footer module), causing the whole suite (not just one test) to fail to load — reported as \"(0 test)\" by Vitest.","author":{"url":"https://github.com/LuisEscamillaMartin","@type":"Person","name":"LuisEscamillaMartin"},"datePublished":"2026-09-29T09:12:58Z","url":"https://github.com/angular/angular-cli/issues/34198"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:2962b3e6-ce00-9b1d-e20d-4379a71ab171 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C36E:2F9718:2CD5877:3C2616C:6B01E08F |
| html-safe-nonce | 24177a1330f0c0c87fd67a7f0a0a39107a53c7f56fba922773eb7665d44e20fb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzZFOjJGOTcxODoyQ0Q1ODc3OjNDMjYxNkM6NkIwMUUwOEYiLCJ2aXNpdG9yX2lkIjoiODM3ODEyNTYwNTgyODQxOTcyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 892d277fa891c89b72cf779802787ef82eebcd24c8cc9adabca3ef56d2c2ac97 |
| hovercard-subject-tag | issue:5628133900 |
| 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/34198/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1bae46abeb841d8ec9f5471610342368c95de5561e3e823f0bbd0948f7195c7a/angular/angular-cli/issues/34198 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1bae46abeb841d8ec9f5471610342368c95de5561e3e823f0bbd0948f7195c7a/angular/angular-cli/issues/34198 |
| og:image:alt | Command test Is this a regression? Not sure — this may be a regression introduced by the linker rewrite in 22.2.0 ("migrate Angular Linker to oxc-parser and magic-string"), since I have not tested ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | LuisEscamillaMartin |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width