我遇到此错误
nest can't resolve dependencies of the UserService (?,SettingsService). Please make sure that the argument UserModel at index [0] is available in the AuthModule context.
Potential solutions:
- If UserModel is a provider,is it part of the current AuthModule?
- If UserModel is exported from a separate @Module,is that module imported within AuthModule?
@Module({
imports: [ /* the Module containing UserModel */ ]
})
auth.module.ts
@Module({
imports: [
PassportModule.register({ defaultStrategy: 'jwt' }),JwtModule.register({
secretOrPrivateKey: config.auth.secret,signOptions: {
expiresIn: config.auth.expiresIn,},}),UserModule,SettingsModule,],controllers: [AuthController],providers: [
AuthService,JwtStrategy,LocalStrategy,UserService,SettingsService,Logger,... other services,exports: [PassportModule,AuthService],})
export class AuthModule {}
user.module.ts
@Module({
imports: [
MongooseModule.forFeature([{ name: 'User',schema: UserSchema }]),controllers: [UserController],providers: [UserService],exports: [UserService],})
export class UserModule {}
app.module.ts
@Module({
imports: [
AuthModule,MongooseModule.forRoot(config.db.url),Winstonmodule.forRoot({
level: config.logger.debug.level,controllers: [AppController],providers: [AppService],})
export class AppModule {}
user.service.ts
@Injectable()
export class UserService {
constructor(@InjectModel('User') private readonly userModel: Model<User>,private readonly settingsService: SettingsService) {}
public async create(user: any): Promise<UserDto> {
...
}
我尝试了所有操作,但找不到问题,一切似乎都正确,我什至检查了每个Google网页结果以尝试找到它,但我被卡住了。 该错误告诉我我需要将UserModel导入AuthModule,但是它已经在那里,我试图删除每个用户模型或AuthModule并将它们混合到所有内容中,但仍然无法正常工作,我知道我必须将UserService导出到AuthModule ,但找不到正确的方法。