You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ng add @angular/ssr fails with TypeError when an NgModule in the app module file has no bootstrap array #34761
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 ea1143d, 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 of bootstrap: [...] (Angular Elements apps, AngularJS hybrid apps that bootstrap through UpgradeModule).
The file declares another @NgModule without bootstrap (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:
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, remove bootstrap: [App] and add ngDoBootstrap() {} to AppModule.
ng add @angular/ssr
Or, for case 2, keep bootstrap: [App] and put this above AppModule in the same file:
@NgModule({exports: []})exportclassSharedModule{}
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)
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.
Activity