admin管理员组文章数量:1434125
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.
本文标签:
版权声明:本文标题:javascript - Nest can't resolve dependencies of the MongooseCoreModule (MongooseConnectionName, ?) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744148065a2592929.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论