JaffParker
JaffParker

Reputation: 716

Injection of a provider from the same module: can't resolve dependencies

Bug Report

Current behavior

Getting error while instantiating the PaymentProcessorModule:

Error: Nest can't resolve dependencies of the PaymentProcessor (?, PaymentsService, ProcessingService). Please make sure that the argument TransactionsService at index [0] is available in the PaymentProcessor context.

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

However, both services come from the same module.

Input Code

Here's my module:

@Module({
  imports: [
    TypeOrmModule.forFeature([ Transaction ]),
  ],
  providers: [
    PaymentProcessor,
    TransactionsService,

    TransactionsResolver,
  ],
  exports: [PaymentProcessor],
})
export class PaymentProcessorModule {}

TransactionService:

@Injectable()
export class TransactionsService {
  constructor(
    @InjectRepository(Transaction) private transRepo: Repository<Transaction>,
  ) {}

  //...
}

And finally, PaymentProcessor:

@Injectable()
export class PaymentProcessor {
  constructor(
    private transactions: TransactionsService,
    private payments: PaymentsService,
    private processor: ProcessingService,
  ) {}

  //...
}

Expected behavior

Expected to inject the TransactionsService. I could not seem to reproduce it in a sample repo, unfortunately.

Environment

Nest version: 7.4.1

Upvotes: 0

Views: 487

Answers (1)

JaffParker
JaffParker

Reputation: 716

The official support of NestJS told me that the PaymentProcessor must be mentioned in the imports array somewhere. I checked for usages of the class and it's true, I accidentally imported the provider instead of the module in another context.

Upvotes: 1

Related Questions