Skip to content
Latchkey

NestJS "UnknownDependenciesException" in CI

UnknownDependenciesException is the underlying error class Nest throws when the injector meets a token it cannot resolve. It names the injectable and the argument index that failed.

What this error means

Bootstrap or a test fails with "UnknownDependenciesException [Error]: Nest can't resolve dependencies of the X". A custom injection token or a class that was never registered as a provider is the usual trigger.

NestJS
UnknownDependenciesException [Error]: Nest can't resolve dependencies of the
ReportService (?, ConfigService). Please make sure that the argument
"PDF_RENDERER" at index [0] is available in the ReportModule context.

Common causes

A custom provider token is not registered

You inject with @Inject('PDF_RENDERER') but no provider uses that exact string or symbol token in the module.

A class is injected without @Injectable or a providers entry

A class used as a dependency is missing the @Injectable() decorator or is not in any module's providers, so Nest has no metadata to construct it.

How to fix it

Register the custom token as a provider

  1. Match the @Inject(TOKEN) string or symbol to a provide: entry exactly.
  2. Add the custom provider to the module that hosts the consumer.
  3. Re-run so the injector can resolve the token.
report.module.ts
@Module({
  providers: [
    { provide: 'PDF_RENDERER', useClass: PdfRenderer },
    ReportService,
  ],
})
export class ReportModule {}

Add @Injectable and register the class

Decorate the dependency and list it in providers so Nest emits the constructor metadata it needs.

pdf-renderer.ts
@Injectable()
export class PdfRenderer {}

How to prevent it

  • Use a shared constant for custom injection tokens so provide and inject cannot drift.
  • Decorate every provider with @Injectable().
  • Cover module wiring with a compiling TestingModule in CI.

Related guides

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