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
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- angular, typescript
- Lĩnh vực
- build-system, testing-qa
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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). CascadeSelectSubis declared earlier in the file thanCascadeSelect, and its factory'sdepsarray referencesCascadeSelectby identifier without going throughforwardRef.- 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.
- Ngôn ngữ chính
- TypeScript
- Star
- 27k
- Fork
- 11.8k
- Merge trung bình
- 21 giờ 31 phút
- Pull request đã merge (30 ngày)
- 168
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của angular/angular-cli
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-serverĐang mởarea: @angular/build gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
angular/angular-cli#33955 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: @angular/cli gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
angular/angular-cli#33055 · 1 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
angular/angular-cli#34207 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
library builder: tslib is not added to the output package.jsonCó thể đã có người làm @alan-agius4 đã nhận 10 ngày trước. Đang mởangular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
library builder: a name re-exported through two "export *" paths is dropped from the bundleCó thể đã có người làm @alan-agius4 đã nhận 10 ngày trước. Đang mởangular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của angular/angular-cli
Issue tương tự
-
bug via-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pingdotgg/t3code#14452 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
solana-foundation/program-examples#747 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 9 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
remotion-dev/remotion#11847 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openwatersio/slackwater#355 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
melgarafael/DeskcommCRM#1998 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày