You can use NestJS's forwardRef function to resolve circular dependencies:
And inside PostsModule, do the same:
This tells NestJS to resolve the modules later, preventing the circular import from crashing the app.
asked about 1 year ago
1
70
I have two services in NestJS: UsersService and PostsService. They depend on each other, which causes a circular dependency error when starting the app. What is the best practice to handle this kind of situation in NestJS?
You can use NestJS's forwardRef function to resolve circular dependencies:
And inside PostsModule, do the same:
This tells NestJS to resolve the modules later, preventing the circular import from crashing the app.
1