Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#34,198 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃

调研方向

Start with the @angular/build:unit-test builder and the emitted node_modules/@openng/optimus-ui/fesm2022/openng-optimus-ui-cascadeselect.mjs file, focusing on the OXC-based Angular linker handling of the partial declarations for CascadeSelectSub and CascadeSelect. Compare this path with the classic Karma pipeline. Done means the affected import graph loads without the ReferenceError and the unit-test suite reports its tests instead of zero.

由索引模型根据 Issue 内容生成。

描述

area: @angular/build gemini-triaged
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 in which this bug was not present was

No response

Description

When 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:

ReferenceError: Cannot access 'CascadeSelect' before initialization
at CascadeSelectSub.<static_initializer> node_modules/@openng/src/cascadeselect/cascadeselect.ts:131:30

I traced this to the actual shipped file (the path above is a sourcemap reference, not a real file on disk):
node_modules/@openng/optimus-ui/fesm2022/openng-optimus-ui-cascadeselect.mjs

In that file, CascadeSelectSub is declared at line 176, and its static Ivy partial declaration at line 274 includes:

static ɵfac = i0.ɵɵngDeclareFactory({ ..., type: CascadeSelectSub, deps: [{ token: CascadeSelect }], target: i0.ɵɵFactoryTarget.Component });

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.

This 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.

Minimal Reproduction

I don't have an isolated reproduction yet, but you've provided the full trace and the exact line of the affected packet.

Exception or Error
ReferenceError: Cannot access 'CascadeSelect' before initialization
❯ CascadeSelectSub.<static_initializer> node_modules/@openng/src/cascadeselect/cascadeselect.ts:131:30
❯ node_modules/@openng/src/cascadeselect/cascadeselect.ts:131:39

(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`.)
Your Environment
Angular CLI: 22.2.0
@angular/build: 22.2.0
Vitest: 5.0.2
Node: v24.21.0
OS: Windows
Anything else relevant?
  • The affected npm package is @openng/optimus-ui (latest version at time of reporting).
  • The broken class is CascadeSelect / CascadeSelectSub, distributed in Ivy partial-compilation format (ɵɵngDeclareComponent, ɵɵngDeclareFactory).
  • CascadeSelectSub is declared earlier in the file than CascadeSelect, and its factory's deps array references CascadeSelect by identifier without going through forwardRef.
  • 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.
  • 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.
主要语言
TypeScript
星标
27k
派生
11.8k
平均合并
21 小时 31 分钟
30 天内合并 PR
168

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

angular/angular-cli 的其他 Issue

查看 angular/angular-cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。