#Error: Nest can't resolve dependencies of the OrderService

11 messages · Page 1 of 1 (latest)

onyx grail
#

Hello, I got this error after adding the fowardRef to my modules, any ideas on how to solve?

Error: Nest can't resolve dependencies of the OrderService (OrderRepository, AttachmentRepository, ApproverService, ?). Please make sure that the argument dependency at index [3] is available in the OrderModule context.

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

Order Module

@Module({
  imports: [
    TypeOrmModule.forFeature([Order, Attachment]),
    ApproverModule,
    forwardRef(() => ApprovementModule),
  ],
  controllers: [OrderController],
  providers: [OrderService],
  exports: [OrderService],
})

Approvement Module

@Module({
  imports: [
    TypeOrmModule.forFeature([Approvement]),
    forwardRef(() => OrderModule),
  ],
  controllers: [ApprovementController],
  providers: [ApprovementService],
  exports: [ApprovementService],
})
ancient pond
#

Can you show the OrderService?

wraith plover
#

You might need to inject whatever you have in the service if you have forwardref in both modules

@Inject(forwardRef(() => WhatCantBeResolved))
onyx grail
# ancient pond Can you show the `OrderService`?
@Injectable()
export class OrderService {
  constructor(
    @InjectRepository(Order)
    private readonly orderRepository: Repository<Order>,

    @InjectRepository(Attachment)
    private readonly attachmentRepository: Repository<Attachment>,

    private readonly approverService: ApproverService,
    private readonly approvementService: ApprovementService,
  ) {}
ancient pond
#

Does ApprovementService inject the OrderService or inject something that eventually does?

onyx grail
#

approvementservice uses orderservice

#

and vice-versa

ancient pond
#

Then you need @Inject(forwardRef(() => OrderService)) and vice versa in the two classes

#

Both modules and both services need that forward ref

onyx grail
#

ooh ok