nestjs - 使用装饰器时,Nestjs 无法解析依赖索引 [0]
问题描述
我是 NestJs 的新手,我有一个无法解决的问题。
UsersService 有两个依赖项
-TypeOrm UsersRepository 注入 -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 */ ]
})
先感谢您。我希望它的描述性足够。有美好的一天!
解决方案
对于来自评论的答案的后代:
数组中有一项服务imports
会导致 Nest 尝试解决问题时出现问题。一般来说,知道 Nest 的错误是以下形式的,就可以开始调试这些错误
Nest 无法解析 UsersService 的依赖项 (<dependencies_with_unknown_as_?>。请确保索引 [] 处的参数 <unknown_dependency> 在 <related_module> 上下文中可用。
推荐阅读
- r - Tidyverse:as.matrix 中的错误:尝试应用非函数
- python-3.x - 如何通过对值求和而不使用 for 循环将 2d numpy 数组转换为 1d numpy 数组?
- python - Tkinter 可变大小列表
- reactjs - 如何通过 props 在另一个 React 组件中添加可选的 React 组件
- angularjs - ng-class 指令条件是否始终显示在 DOM 中?
- c++ - c++指针返回0值
- docker - 使用 COPY --from 覆盖我容器中的二进制文件
- javascript - Reactjs:如何将 .then 获得的结果保存到 var
- android - 为什么 Firebase 无法获取 PlayGames AuthCode 并将其传递到其凭据中?
- python - Python - 保留日期列并使用字段名称翻转单元格