Today I Learned

Resolving "Nest can't resolve dependencies of the X"

From time to time you can see the error:

Nest can’t resolve dependencies of the X. Please make sure that the “Y” property is available in the current context.

In case of services:

  • Ensure the service is exposed in the module
  • Ensure the module exposing the service is included in the module
  • In tests: ensure the service is provided in the createTestingModule function
  • Check for circular dependencies; if you think there is one, use forwardRef in the place where the service is injected: @Inject(forwardRef(() => UserService)) private readonly userService: UserService