NestJSInterview preparation
Foundation·Concept·2 min read

Why does Nest say it cannot resolve a dependency?

Practice this question

Definition:

A dependency-resolution error means Nest cannot find or create a required provider in the current module context. The class may exist in source code but still be invisible to the consumer's module. Troubleshooting should follow the token, registration, export and import path.

Key points:

  • Check that the provider is registered in providers.

  • Export it from its module and import that module where it is needed.

  • Check the injection token and circular dependencies.

  • Interfaces disappear at runtime, so injecting by an interface usually requires an explicit token such as a symbol or string.

Interview point:

  • Avoid fixing every DI error by making modules global; identify the missing dependency boundary.
Adapted from 03_NESTJS.md · “Why does Nest say it cannot resolve a dependency?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.