A
A
alaskafx2022-02-05 15:26:27
Node.js
alaskafx, 2022-02-05 15:26:27

How can I access a service from a Nest service?

I have a PurchaseService that needs to access a second userService .
When I try to import userService into PurchaseService, I get an error like this:

Nest can't resolve dependencies of the PurchaseService (paymentsEntityRepository, ?). Please make sure
 that the argument userService at index [1] is available in the PurchaseModule context.

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

How to solve it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2022-02-05
@alaskafx

In the module where the PurchaseService service is, you need to import the module where the userService service is, or add userService to the providers array of the module where the PurchaseService.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question