MongooseCoreModule unable to resolve ModuleRef from injection container
BitForger opened this issue · 4 comments
Did you read the migration guide?
- I have read the whole migration guide
Is there an existing issue that is already proposing this?
- I have searched the existing issues
Potential Commit/PR that introduced the regression
No response
Versions
7.x -> 9
Describe the regression
I have made it all the way through the migration process up to the point where I'm trying to test in my local environment. When I start the application is gives me this error:
ERROR [ExceptionHandler] 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.
Minimum reproduction code
MongooseModule.forRootAsync({
imports: [EnvModule], // a module importing classes that validate the environment variables
useClass: ConfigService,
connectionName: "dbname",
})
Expected behavior
Application shouldn't error on startup
Other
I'm completely lost as to what the problem could be.
Please provide a minimum reproduction repository.
This seems to be the issue: https://discord.com/channels/520622812742811698/527863537708695562/888102356615569418
Reopening on further investigation. We believe that adding the @Inject
token to the MongooseCoreModule
line here:
mongoose/lib/mongoose-core.module.ts
Line 30 in abd3725
to be
@Inject(<token for ModuleRef>) private readonly moduleRef: ModuleRef
will remedy an issue with that class not knowing how to find it's dependency when pulled in under a monorepo scenario.
We believe this might be related skunight/nestjs-redis#82 (comment)
We believe that adding the @Inject token to the MongooseCoreModule line here:
Adding @Inject()
won't help here.
Just make sure that all @nestjs
packages are installed as peer dependencies. Please search through some of our old issues on this (this has been discussed several times in the past).