使用装饰器时,Nestjs无法解析依赖项索引[0]

时间:2020-06-28 11:02:49

标签: nestjs typeorm

我是NestJs的新手,我有一个问题无法解决。

UsersService具有两个依赖项

-TypeOrm用户存储库注入 -WalletsService注入

Typeorm注入是由装饰器完成的,如下所示。

//UsersService
@Injectable()
export class UsersService implements IUserService {
  constructor(
    @InjectRepository(Users)
    private usersRepository: Repository<Users>,
    private readonly walletsService: WalletsService,
  ) { }

每当我更改第一次注射时,都无法解决。

可能我错过了一些东西。以下是所有带有说明的照片

//UsersModule
@Module({
  controllers: [UsersController],
  exports: [UsersService],
  imports: [WalletsModule, TypeOrmModule.forFeature([Users])],
  providers: [UsersService],
})

export class UsersModule { }

//WalletsModule
@Module({
  controllers: [WalletsController],
  exports: [WalletsService],
  imports: [TypeOrmModule.forFeature([Wallets])],
  providers: [WalletsService]
})

export class WalletsModule { }

[首次注入用户存储库时]

Nest can't resolve dependencies of the UsersService (?, WalletsService). Please make sure that the argument UsersRepository at index [0] is available in the UsersService context.

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

[首次注入电子钱包服务时]

Nest can't resolve dependencies of the UsersService (?, UsersRepository). Please make sure that the argument WalletsService at index [0] is available in the UsersService context.

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

先谢谢您。我希望它具有足够的描述性。祝你有美好的一天!

1 个答案:

答案 0 :(得分:0)

对于评论中答案的后代:

imports数组中有一个服务,这导致Nest尝试解决问题时遇到了问题。通常,知道Nest的错误为

形式后,就可以开始调试这些错误了。

嵌套无法解析UsersService的依赖项(。请确保索引[]处的参数上下文中可用。