@Wadnory

Как победить циркулярную зависимость (если это она)?

648dd57ae1661564218052.png

Код выдает такую ошибку:
[Nest] 11732  - 17.06.2023, 18:30:35   ERROR [ExceptionHandler] Nest can't resolve dependencies of the ComplaintsService (ComplaintRepository, ?). Please make sure that the argument dependency at index [1] is available in the
in the ComplaintsModule context.

Potential solutions:
- Is ComplaintsModule a valid NestJS module?
- If dependency is a provider, is it part of the current ComplaintsModule?
- If dependency is exported from a separate @Module, is that module imported within ComplaintsModule?
  @Module({
    imports: [ /* the Module containing dependency */ ]
  })

Error: Nest can't resolve dependencies of the ComplaintsService (ComplaintRepository, ?). Please make sure that the argument dependency at index [1] is available in the ComplaintsModule context.

Potential solutions:
- Is ComplaintsModule a valid NestJS module?
- If dependency is a provider, is it part of the current ComplaintsModule?
- If dependency is exported from a separate @Module, is that module imported within ComplaintsModule?
  @Module({
    imports: [ /* the Module containing dependency */ ]
  })


Bing ai подсказывает что проблема в циркулярной зависимости, но я во всех трех модулях указал forwarRef. Так в чем же проблема? Подскажите пожалуйста
  • Вопрос задан
  • 111 просмотров
Решения вопроса 1
@Wadnory Автор вопроса
Я не нашел ответ на вопрос, поэтому просто пределал проект так, чтобы не было циркулярной зависимости
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
@KrainovSD
@Injectable()
export class ComplaintService {
   constructor(
       @InjectModel(Complaint) private complaintRepository: typeof Complaint,
       @Inject(forwardRef(() => PostsService)) - При добавлении сервиса из модуля, который участвует в циркулярной зависимости, попробуй добавить следующее
       private postsService: PostsService
   )
}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы