ng add @angular/ssr fails with TypeError when an NgModule in the app module file has no bootstrap array
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 90/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- angular, typescript
- Bereich
- build-system, tooling
Rechercherichtung
Beginne in packages/schematics/angular/utility/standalone/app_component.ts, in resolveNgModuleBasedData, und untersuche, wie @NgModule-Dekoratoren ohne ein bootstrap-Feld behandelt werden. Lies die vorhandenen Prüfungen in der Nähe und überprüfe anschließend die Abdeckung des Server-Schematics in server/index_spec.ts. Fertig ist die Änderung, wenn Dekoratoren ohne bootstrap übersprungen werden, sich die beiden gemeldeten Fälle wie beschrieben verhalten und die gezielten Tests bestehen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 27k
- Forks
- 11.8k
- Ø Merge
- 1 T. 2 Std.
- Gemergte PRs (30 T.)
- 225
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus angular/angular-cli
-
`@angular/[email protected]` depends on vulnerable Vite 7.3.7 - GHSA-p4f5-76q4-ffq7 (Critical RCE)Offenarea: @angular/build
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
angular/angular-cli#34764 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
angular/angular-cli#34760 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Angular SSR can crash `AngularAppEngine` servers with a single aborted request (22.2.6 regression)Evtl. vergeben @SkyZeroZx hat das vor 1 Tag übernommen. Offenarea: @angular/ssr
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 20/100
angular/angular-cli#34754 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: @schematics/angular
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 74/100
angular/angular-cli#34730 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: @angular/build
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
angular/angular-cli#34728 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in angular/angular-cli
Ähnliche Issues
-
status/need-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
google-gemini/gemini-cli#30384 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
P2
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug ready-for-human
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 60/100
LucasSantana-Dev/Lucky#3150 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement good first issue priority: low size: XS
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
vercel-labs/scriptc#3979 ·
Maintainer antworten meist innerhalb von 1 Tag