使用装饰器时,Nestjs 无法解析依赖项索引 [0]
Nestjs cannot resolve dependency index[0] when decorator is being used
我是 NestJs 的新手,我有一个我无法解决的问题要问你。
UsersService 有两个依赖项
-TypeOrm UsersRepository 注入
-钱包服务注入
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 { }
[首次注入Users Repository时]
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 */ ]
})
提前谢谢你。我希望它具有足够的描述性。祝你有美好的一天!
对于评论中答案的后代:
imports
数组中有一项服务导致 Nest 尝试解决问题。一般来说,知道Nest的报错形式是
就可以开始调试这些报错了
Nest can't resolve dependencies of the UsersService (<dependencies_with_unknown_as_?>. Please make sure that the argument <unknown_dependency> at index [] is available in the <related_module> context.
我是 NestJs 的新手,我有一个我无法解决的问题要问你。
UsersService 有两个依赖项
-TypeOrm UsersRepository 注入 -钱包服务注入
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 { }
[首次注入Users Repository时]
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 */ ]
})
提前谢谢你。我希望它具有足够的描述性。祝你有美好的一天!
对于评论中答案的后代:
imports
数组中有一项服务导致 Nest 尝试解决问题。一般来说,知道Nest的报错形式是
Nest can't resolve dependencies of the UsersService (<dependencies_with_unknown_as_?>. Please make sure that the argument <unknown_dependency> at index [] is available in the <related_module> context.