Nest can't resolve dependencies of the MongooseCoreModule (MongooseConnectionName, ?). Please make sure that the argument ModuleRef at index [1] is available in the MongooseCoreModule context.
I am new to nest and am facing this issue, the app.controller.ts is
import { Module } from '@nestjs/mon';
import { ItemsController } from './items.controller';
import { ItemsService } from './items.service';
import { MongooseModule } from '@nestjs/mongoose';
import { ItemSchema } from './schema/item.schema';
@Module({
imports: [MongooseModule.forFeature([{name:'Item',schema:ItemSchema}])],
controllers: [ItemsController],
providers: [ItemsService],
})
export class ItemsModule {}
Any help would be appreciated
Nest can't resolve dependencies of the MongooseCoreModule (MongooseConnectionName, ?). Please make sure that the argument ModuleRef at index [1] is available in the MongooseCoreModule context.
I am new to nest and am facing this issue, the app.controller.ts is
import { Module } from '@nestjs/mon';
import { ItemsController } from './items.controller';
import { ItemsService } from './items.service';
import { MongooseModule } from '@nestjs/mongoose';
import { ItemSchema } from './schema/item.schema';
@Module({
imports: [MongooseModule.forFeature([{name:'Item',schema:ItemSchema}])],
controllers: [ItemsController],
providers: [ItemsService],
})
export class ItemsModule {}
Any help would be appreciated
Share Improve this question asked Feb 3, 2022 at 23:05 LdrLdr 612 silver badges6 bronze badges 3-
2
this is likely due to multiple modules loaded for the same
@nestjs/core
package. If you're in a monorepo, see this: github./nestjs/docs.nestjs./pull/2152/files – Micael Levi Commented Feb 3, 2022 at 23:18 - I think my error is first one, how to resolve that? – Ldr Commented Feb 3, 2022 at 23:20
-
not having
@nestjs/core
as hard dependency in your side. Without context, it's hard to tell why you end up with many@nestjs/core
. – Micael Levi Commented Feb 4, 2022 at 0:49
5 Answers
Reset to default 1In you case, you can try to add this to your ItemSchema :
// schema/item.schema
@Schema({ collection: 'items' })
And make sure the import with a plural name :
// items.module.ts
// [...]
@Module({
imports: [MongooseModule.forFeature([{name:'items',schema:ItemSchema}])],
controllers: [ItemsController],
providers: [ItemsService],
})
export class ItemsModule {}
According to this question.
Or if you prefer to keep the name schema name item
, you can force it by following this answer
Mongoose is trying to be smart by making your collection name plural. You can however force it to be whatever you want:
var dataSchema = new Schema({..}, { collection: 'data' })
I faced this error while i am learning Connecting Nest.js with Azure Cosmos DB. Error : "Nest can't resolve dependencies of the AzureCosmosDbCoreModule (COSMOS_DB_CONNECTION_NAME, ?). Please make sure that the argument ModuleRef at index [1] is available in the AzureCosmosDbCoreModule context.
Potential solutions:
- Is AzureCosmosDbCoreModule a valid NestJS module?
- If ModuleRef is a provider, is it part of the current AzureCosmosDbCoreModule?
- If ModuleRef is exported from a separate @Module, is that module imported within AzureCosmosDbCoreModule?
@Module({
imports: [ /* the Module containing ModuleRef */ ]
})"
Here is the solution:
Check your dependencies in the Package.json file.
"dependencies": {
"@azure/cosmos": "^3.17.3",
"@nestjs/azure-database": "^2.3.0",
"@nestjs/mon": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"dotenv": "^16.1.4",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0"
},
"overrides": {
"@nestjs/azure-database": {
"@nestjs/mon": "^9.1.4",
"@nestjs/core": "^9.1.4"
}
This may help you!.
This error occurs when you dont start
your code in the proper directory in your program folder. So cd
navigate to the directory of your project and and run all the codes again.
It happens when you have @nestjs/core and @nestjs/mons installed with different versions.
Try deleting node_modules
and run npm/yarn/pnpm install
. It worked for my project.