Skip to content

NestFactory.create never return or throw on error #15245

@LaGregance

Description

@LaGregance

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When we call NestFactory.create with a provider that throw an error, the function never return or throw.

Minimum reproduction code

https://github.com/LaGregance/nestjs-create-never-returns

Steps to reproduce

The reproduction repository add a typeorm connection on the app.module using TypeOrmModule.forRoot, because the database doesn't exists, we see an error in the console (firsts errors are from TypeOrmModule because the module retry the connection, last error is on ExceptionHandler).

The point here is the NestFactory.create function never return in that case and we have no way to manage error (such error in production may need to be send to a monitoring system, especially when using multiple application instances).

This is the main.ts so you can understand the point:

async function bootstrap() {
  try {
    const app = await NestFactory.create(AppModule);
    console.log('[CREATED] This never happen');
    await app.listen(process.env.PORT ?? 3000);
  } catch (error) {
    console.log('[CATCH] This never happen');
    console.error(error);
  }
  console.log('[END] This never happen');
}
bootstrap();

Expected behavior

The NestFactory.create should throw the error.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

@nestjs/typeorm

NestJS version

11.0.1

Packages versions

[System Information]
OS Version     : macOS24.5.0
NodeJS Version : v22.14.0
YARN Version    : 1.22.22 

[Nest CLI]
Nest CLI Version : 11.0.7 

[Nest Platform Information
platform-express version : 11.1.3
schematics version       : 11.0.5
typeorm version          : 11.0.0
testing version          : 11.1.3
common version           : 11.1.3
core version             : 11.1.3
cli version              : 11.0.7

Node.js version

22.14.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue has not been looked into

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions