Skip to content
Latchkey

NestJS "Nest application failed to start" in CI

Nest aborted bootstrap because a module or lifecycle hook threw while initializing. This line is a summary; the actual exception (a DB connect, a missing env, an onModuleInit throw) is logged immediately before it.

What this error means

Startup ends with "Error: Nest application failed to start" preceded by a stack trace from a provider's onModuleInit or an async module factory.

NestJS
[Nest] ERROR [ExceptionHandler] connect ECONNREFUSED 127.0.0.1:6379
Error: Nest application failed to start
    at NestApplication.listen (/app/node_modules/@nestjs/core/nest-application.js:...)

Common causes

A lifecycle hook threw during init

An onModuleInit or onApplicationBootstrap that connects to a dependency (Redis, a DB) failed, aborting the whole startup.

An async module factory rejected

A forRootAsync factory threw (a missing env, a bad URL), so the module could not be constructed.

How to fix it

Read the error logged above the summary

  1. Scroll up to the exception printed just before "failed to start".
  2. Fix the underlying cause (start the dependency service, provide the env).
  3. Re-run bootstrap to confirm the module initializes.

Provide dependencies the init hooks need

If a hook connects to a service, ensure that service is available in CI before the app starts.

.github/workflows/ci.yml
services:
  redis:
    image: redis:7
    ports: ['6379:6379']

How to prevent it

  • Provision every external dependency an init hook needs in the CI job.
  • Fail with a clear message inside init hooks so the root cause is obvious.
  • Smoke-test bootstrap in CI so init failures are caught before deploy.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →