nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.92k stars 7.55k forks source link

LazyModuleLoader not available in lazily loaded module #10421

Closed advancingu closed 1 year ago

advancingu commented 1 year ago

Is there an existing issue for this?

Current behavior

Have a lazily loaded module LazyModule and a service LazyService inside it that itself wants to use LazyModuleLoader to load further modules.

Running an application like this fails with an error:

Error: Nest can't resolve dependencies of the LazyService (?). Please make sure that the argument LazyModuleLoader at index [0] is available in the LazyModule context.

Minimum reproduction code

https://stackblitz.com/edit/nestjs-typescript-starter-1eknf8?file=src/app.module.ts

Steps to reproduce

  1. Run the reproduction code.
  2. See error message in console.

Expected behavior

LazyModuleLoader should be usable in services of modules that were lazy loaded.

Package

Other package

No response

NestJS version

^9.0.0

Packages versions

{
    "@nestjs/common": "^9.0.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/platform-express": "^9.0.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.4.0"
}

Node.js version

No response

In which operating systems have you tested?

Other

Potentially the same issue as in https://github.com/nestjs/nest/issues/9622.

micalevisk commented 1 year ago

Looks like we can't inject LazyModuleLoader in lazy-loaded providers. Not sure if this is the intended behavior tho.

kamilmysliwiec commented 1 year ago

Let's track this here https://github.com/nestjs/nest/issues/9622