ng add @angular/ssr fails with TypeError when an NgModule in the app module file has no bootstrap array
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 90/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- angular, typescript
- Lĩnh vực
- build-system, tooling
Hướng nghiên cứu
Bắt đầu tại packages/schematics/angular/utility/standalone/app_component.ts, trong resolveNgModuleBasedData, và kiểm tra cách xử lý các decorator @NgModule không có trường bootstrap. Đọc các kiểm tra hiện có ở gần đó, sau đó xem lại phạm vi kiểm thử của schematic phía máy chủ trong server/index_spec.ts. Hoàn thành khi các decorator không có bootstrap được bỏ qua, hai trường hợp được báo cáo hoạt động như mô tả và các bài kiểm thử tập trung đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Command
add
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
I think before the server schematic started inferring the app component name (commit ea1143dd, April 2025). I have not run an older release to confirm.
Description
ng add @angular/ssr (and ng generate server) crashes on an NgModule-based app when one of the @NgModule decorators in the file that main.ts bootstraps has no bootstrap array. The cases I hit:
- The root module uses
ngDoBootstrap()instead ofbootstrap: [...](Angular Elements apps, AngularJS hybrid apps that bootstrap throughUpgradeModule). - The file declares another
@NgModulewithoutbootstrap(for example a small shared module) before the root module.
In packages/schematics/angular/utility/standalone/app_component.ts, resolveNgModuleBasedData loops over the module's @NgModule decorators and does:
const bootstrapProp = getMetadataField(node, 'bootstrap').find(...);
const componentIdentifier = (bootstrapProp?.initializer as ts.ArrayLiteralExpression)
.elements[0] as ts.Identifier | undefined;
When bootstrapProp is undefined, the optional chain stops at initializer and .elements is read from undefined. The function is meant to return null in that case: the caller in server/index.ts already falls back to App / AppModule when nothing is found. So the schematic stops with a TypeError instead of using the fallback (case 1) or the right module (case 2).
Minimal Reproduction
ng new demo --no-standalone- In
src/app/app-module.ts, removebootstrap: [App]and addngDoBootstrap() {}toAppModule. ng add @angular/ssr
Or, for case 2, keep bootstrap: [App] and put this above AppModule in the same file:
@NgModule({ exports: [] })
export class SharedModule {}
I reproduced this with SchematicTestRunner against @schematics/angular 22.3.0 (workspace -> application --standalone=false -> edit the module -> server and ssr schematics). Both schematics throw for case 1, and server throws for case 2. The unmodified app works.
Exception or Error
TypeError: Cannot read properties of undefined (reading 'elements')
at resolveNgModuleBasedData (node_modules/@schematics/angular/utility/standalone/app_component.js:65:14)
Your Environment
@schematics/angular 22.3.0
@angular-devkit/schematics 22.3.0
Node.js 22.23.5
Anything else relevant?
Skipping decorators that have no bootstrap field (continue, like the ts.isObjectLiteralExpression check just above it) is enough to fix both cases: case 2 then finds AppModule, and case 1 falls through to the existing fallback. I have a patch with two tests in server/index_spec.ts and can open a PR.
- Ngôn ngữ chính
- TypeScript
- Star
- 27k
- Fork
- 11.8k
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 225
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
-
`@angular/[email protected]` depends on vulnerable Vite 7.3.7 - GHSA-p4f5-76q4-ffq7 (Critical RCE)Đang mởarea: @angular/build
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
angular/angular-cli#34764 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
angular/angular-cli#34760 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Angular SSR can crash `AngularAppEngine` servers with a single aborted request (22.2.6 regression)Có thể đã có người làm @SkyZeroZx đã nhận 1 ngày trước. Đang mởarea: @angular/ssr
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
angular/angular-cli#34754 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: @schematics/angular
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 74/100
angular/angular-cli#34730 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: @angular/build
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
angular/angular-cli#34728 · 2 bình luận ·
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ự
-
status/need-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
google-gemini/gemini-cli#30384 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
P2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug ready-for-human
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
LucasSantana-Dev/Lucky#3150 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement good first issue priority: low size: XS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
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 78/100
vercel-labs/scriptc#3979 ·
Maintainer thường phản hồi trong vòng 1 ngày