Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependencies are not resolved when using lazy load transient providers #13761

Open
2 of 15 tasks
thnam1410 opened this issue Jul 6, 2024 · 3 comments · May be fixed by #13804
Open
2 of 15 tasks

Dependencies are not resolved when using lazy load transient providers #13761

thnam1410 opened this issue Jul 6, 2024 · 3 comments · May be fixed by #13804
Labels
needs triage This issue has not been looked into

Comments

@thnam1410
Copy link

thnam1410 commented Jul 6, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When I lazy loading and resolve module/provider with transient provider and some singleton sub providers. The first exec function (API call) it works fine. But the second exec of itself, the injected providers (in this case is "B") is undefined.

When I tried to cache the result of .load() and reuse it. It works, but I'm not sure if there is a issue behind the screen that I'd have not known it yet.

Minimum reproduction code

https://stackblitz.com/edit/nestjs-typescript-starter-nzzyej?file=src%2Fapp.controller.ts

Steps to reproduce

Not-working endpoint: /not-work
Working endpoint: /work

Expected behavior

I expect that when using resolve, it creates a transient provider as my use case and all sub-dependencies as "Singleton" won't be re-created

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

No response

Packages versions

@nestjs/core: 10.3.0

Node.js version

20.10.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@thnam1410 thnam1410 added the needs triage This issue has not been looked into label Jul 6, 2024
@micalevisk
Copy link
Member

micalevisk commented Jul 6, 2024

image

somehow it is loosing that reference

repro

I tested with nestjs v9 as well.

@KostyaTretyak
Copy link

KostyaTretyak commented Jul 7, 2024

By the way, in repro, the /work route is identical to the /not-work route. Therefore, you can work with any of them. The first request is successful, the second - unsuccessful.

@micalevisk
Copy link
Member

micalevisk commented Jul 7, 2024

this seems to be a bug with lazyModuleLoader#load when the module is resolved already (cached) because it works as expected when lazyModuleLoader#load returns a new instance every time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
3 participants