-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Unexpected circular dependency error #1614
Comments
Trying to solve my issue, I'm discovered that if I import the modules directly (instead of using the So as a fix, I've found a solution. I just have to replace my module imports with this: api.module.ts import { AuthModule } from '@modules/auth/auth.module';
import { UserModule } from '@modules/user/user.module';
... auth.module.ts import { UserModule } from '@modules/user/user.module';
... But still, I'm curious to understand why there is an issue with my first approach. I guess I've misunderstood something about Nest dependencies or maybe it's not Nest related at all and just the way imports work in Node.js / TypeScript environment. And if so, I'm curious to know if there is a way to gather all declarations living in a directory (here, So if anyone has any input or explanation about this behaviour, it would be very welcomed! :) And besides, the Nest framework and the way it is lead are very promising and interesting! Dziękuję @kamilmysliwiec ! |
Dziękuje @LandazuriPaul! :) I'm glad that you found a solution. Here you can read more about this issue: #1181 |
Thanks for the issue reference! I'll read about barrel files and its implications. I didn't know about all the outcomes tied to them. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm submitting a...
Current behavior
Nest throws an error about a circular dependency that doesn't exist. Here is the error thrown:
Nest cannot create the module instance. Often, this is because of a circular dependency between modules. Use forwardRef() to avoid it. (Read more https://docs.nestjs.com/fundamentals/circular-dependency.) Scope [APIModule -> AuthModule]
Expected behavior
From what I understand about circular dependency, there isn't any in the situation described, so Nest should be able to create the module instance.
Minimal reproduction of the problem with instructions
api.module.ts
auth.module.ts
user.module.ts
And for more information, here are the 2 services:
auth.service.ts
user.service.ts
Environment
The text was updated successfully, but these errors were encountered: