Skip to content

Error in an async lifecycle hook and router ResolveFn crashes Angular 16 universal server #50457

@moonseob

Description

@moonseob

Which @angular/* package(s) are the source of the bug?

platform-server

Is this a regression?

Yes

Description

스크린샷 2023-05-25 10 34 04

The node server built by nguniversal/express-engine crashes seems to be failing to handle errors correctly.

Reproduction

  1. ng add @nguniversal/express-engine
  2. Throw an error in any async function
export class AppComponent implements OnInit {
  async ngOnInit() {
    throw new Error('');
  }
  // or
  ngOnInit() {
    new Promise((_, reject) => reject(''));
  }
}
  1. Build and run the universal server (i.e. npm run serve:ssr)
  2. The node server crashes when it tries to run the code.

The same procedure the dependencies of Angular 15 does not crash the server.

Please provide the exception or error you saw

Node.js v18.16.0
A server error has occurred.
node exited with 1 code.

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 16.0.2
Node: 18.16.0
Package Manager: npm 9.5.1
OS: darwin arm64

Angular: 16.0.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1600.2
@angular-devkit/build-angular   16.0.2
@angular-devkit/core            16.0.2
@angular-devkit/schematics      16.0.2
@angular/cli                    16.0.2
@nguniversal/builders           16.0.2
@nguniversal/express-engine     16.0.2
@schematics/angular             16.0.2
rxjs                            7.8.1
typescript                      5.0.4

Anything else?

  ngOnInit() {
    throw new Error('');
    // or
    throwError(() => '').subscribe();
  }

In case of "sync" function or an observble, the server does not crash and serves the html just fine.

스크린샷 2023-05-25 10 49 43

Metadata

Metadata

Assignees

Labels

area: coreIssues related to the framework runtimearea: routerarea: serverIssues related to server-side renderingarea: zonesIssues related to zone.jsregressionIndicates than the issue relates to something that worked in a previous version

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions