I have created a new NestJS v9 project, reusing a WORKING module from my previous NestJS v8.2.4 (as part of my research on upgrading to NestJS v9 eventually) but it doesn't compile, claiming it can't find my imported Mongoose model (happens with any module that has a model):
Nest can't resolve dependencies of the SystemService (?). Please make sure that the argument SystemConfigModel at index [0] is available in the SystemModule context.
I've created a sample based on the nestjs tutorial (using cats module instead of my system module) in code sandbox where the error is reproduced
app module:
@Module({
imports: [
SystemModule,
MongooseModule.forRoot(`mongodb://localhost/db1`, {
connectionName: 'mydb',
}),
],
controllers: [AppController],
providers: [AppService, AppResolver],
})
export class AppModule {}
system module (listing all classes together):
export type SystemConfigDocument = mongoose.HydratedDocument<SystemConfig>;
@Schema()
export class SystemConfig {
@Prop()
key: string;
@Prop()
value: string;
}
export const SystemConfigSchema = SchemaFactory.createForClass(SystemConfig);
@Module({
imports: [
MongooseModule.forFeature(
[
{
name: SystemConfig.name,
schema: SystemConfigSchema,
collection: 'systemConfig',
},
],
'mydb',
),
],
providers: [SystemService],
exports: [SystemService],
})
export class SystemModule {}
@Injectable()
export class SystemService {
constructor(
@InjectModel(SystemConfig.name) private systemConfigModel: Model<SystemConfig>,
) {}
}