#TestModule error with forwardRef

12 messages · Page 1 of 1 (latest)

brazen crystal
#
    @InjectRepository(WalletTransaction, 'pg-wallet')
    @Inject(forwardRef(() => WalletService))

that's wrong

#

should be:

    @Inject(forwardRef(() => WalletService))
    private readonly walletService: WalletService,
    @InjectRepository(WalletTransaction, 'pg-wallet')
    private walletTransactionRepository: Repository<WalletTransaction>,
pure bone
#

I have updated this:

export class WalletTransactionService {
  constructor(
    @InjectRepository(WalletTransaction, 'pg-wallet')
    private walletTransactionRepository: Repository<WalletTransaction>,
    @Inject(forwardRef(() => WalletService))
    private readonly walletService: WalletService,
    private readonly notificationGateway: NotificationGateway,
    private readonly metricsService: MetricsService,
    private readonly bankService: BankService,
    private readonly userService: UserService,
  ) {}

Now I get an error:

Nest can't resolve dependencies of the WalletTransactionService (pg-wallet_WalletTransactionRepository, WalletService, NotificationGateway, MetricsService, BankService, ?). Please make sure that the argument dependency at index [5] is available in the RootTestModule context.

My module looks like this:

@Module({
  imports: [
    // .. other imports,
    forwardRef(() => UserModule),
  ],
  // ...,
})

Why do I get an error from a service whose module is imported via forwardRef?

#

@brazen crystal

brazen crystal
#

because of UserService being circular, I guess

pure bone
#

User module

@Module({
  imports: [
    forwardRef(() => WalletModule),
  ],
  providers: [UserService, UserProcessor],
  exports: [UserRepositories, UserService],
})
export class UserModule {}
brazen crystal
#

use forwardRef for that injected UserService as well

pure bone
brazen crystal
#

no

#

it's on the docs

verbal shellBOT
#

This post has been marked as resolved. :white_check_mark:
Please read through the conversation and resolution if you are having the same issue, and then re-open the post if you are still having trouble, providing as much extra information as possible.

pure bone