【发布时间】:2020-01-14 19:13:55
【问题描述】:
我的 Nest 应用程序在运行时抛出以下错误
Nest can't resolve dependencies of the UserService (?, UserProfileModel). Please make sure that the argument at index [0] is available in the AuthModule context. +3ms
Error: Nest can't resolve dependencies of the UserService (?, UserProfileModel). Please make sure that the argument at index [0] is available in the AuthModule context.
at Injector.lookupComponentInExports (PATH\node_modules\@nestjs\core\injector\injector.js:183:19)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
对于上下文,我正在尝试使用 Mongoose 与 MongoDB Atlas 建立连接。我发现这个问题的唯一答案是将TypeOrmModule.forFeature([UserModel]) 添加到模块导入中。但是,我认为这在这里无关紧要,因为猫鼬已经这样做了。这里是代码sn-ps
身份验证模块 TS
imports: [
MongooseModule.forFeature([{name: 'User', schema: UserModelSchema}, {name: 'UserProfile', schema: UserProfileModelSchema}])],
controllers: [AuthController],
providers: [UserService],
应用模块 TS
imports: [AuthModule, MongooseModule.forRoot(config.dbServer)],
controllers: [AppController],
providers: [AppService],
})
身份验证服务 TS
constructor(@InjectModel('Users')private readonly users: Model<UserModel>,
@InjectModel('UserProfile') private readonly userProfile: Model<UserProfileModel>){
}
帮助非常感谢
【问题讨论】:
标签: javascript node.js typescript mongoose nestjs