Upgrading to versions greater than 9.0.3 breaks the application
ElecTreeFrying opened this issue ยท 5 comments
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
My nestjs version is at 9.0.8, I don't know why but whenever I update the @nestjs/mongoose
version greater than 9.0.3 it breaks my app. It shows this error.
Error: Nest can't resolve dependencies of the UserRepository (?). Please make sure that the argument UserModel at index [0] is available in the UserModule context.
Potential solutions:
- If UserModel is a provider, is it part of the current UserModule?
- If UserModel is exported from a separate @Module, is that module imported within UserModule?
@Module({
imports: [ /* the Module containing UserModel */ ]
})
I already did update the versions successfully from v7 to v8, and just recently from v8 to v9, and now I'm trying to update to the latest version of v9 and I'm getting these errors.
Other nestjs libraries and dependencies are successfully updated without errors, only the @nestjs/mongoose
gives an error when updating to latest
.
My current version of @nestjs/mongoose
is v9.0.3.
Need help to resolve this issue. Thanks in advance.
Minimum reproduction code
na
Steps to reproduce
No response
Expected behavior
Install @nestjs/mongoose@9.2.0 without issues.
Package version
9.2.0
mongoose version
6.5.1
NestJS version
9.0.8
Node.js version
14.18.1
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response
Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).
Most likely you have a name
element to your MongooseModule.forRoot()
(which is how you tell Nest you want to support multiple database) but you don't have the same name used in your forFeature()
or @InjectModel()
so nest doesn't know how to handle the injected model because it can't be found. Without a reproduction though, I can't say for certain
@jmcdo29 this is my reproduction repo https://github.com/ElecTreeFrying/my-app
Changing the @nestjs/mongoose
to v9.0.3 temporarily removes the error.
As you are using named connections, you need to provide that name in your @InjectModel
as well. @InjectModel(Model, connectionname)
. This isn't a bug, but a misuse of the library
There's no second parameter in v9.0.3, updating to v9.2.0 and adding a second parameter solves the issue.
I think the docs should be updated, some users might encounter this issue.
Thanks for the replies @jmcdo29, I finally resolved my issue.