Giter VIP home page Giter VIP logo

Comments (6)

fasenderos avatar fasenderos commented on July 17, 2024 1

I did not found a solution, so I have to stay with typegoose beta.9 and mongoose 5.12.8

from nestjs-typegoose.

OoDeLally avatar OoDeLally commented on July 17, 2024 1

I had a similar problem, and my mistake was a combination of various bad dependencies.
A - I was trying to export the model, instead of exporting the service.
or
B- I was exporting the service, but was including the service into the user's providers (which leads to a double-instantiation).
If you can create a minimal example, I can have a look, in case you made the same kind of mistakes.

from nestjs-typegoose.

OoDeLally avatar OoDeLally commented on July 17, 2024 1

@GuillaumeGSO You did the same mistake as I did:

@Module({
  imports: [
    TypegooseModule.forRoot(config.mongoURI), CompanyDataModule, NotificationsModule],
  controllers: [
    AppController, // Should be there since it is AppModule's responsibility to instantiate this.
    NotificationsController // Should NOT be here since it is NOT AppModule's responsibility to instantiate this.
  ],
  providers: [
    AppService,// Should be there since it is AppModule's responsibility to instantiate this.
    CompanyDataService, // Should NOT be here since it is NOT AppModule's responsibility to instantiate this. However since this one doesnt have any deps, it doesnt crash. It will be instantiated twice though.
    NotificationService,  // Should NOT be here since it is NOT AppModule's responsibility to instantiate this.
    NotificationDataService // Should NOT be here since it is NOT AppModule's responsibility to instantiate this.
  ],
})
export class AppModule {}

Including services and controllers into the controllers and providers will make Nest try to instantiate them from that module (here AppModule, which should not instantiate them, but merely import them from NotificationModule).
Only NotificationModule does have the required dependencies, and you only need to instanciate them from this module.

Remove the commented lines above, and your code will run.

from nestjs-typegoose.

feliperoan avatar feliperoan commented on July 17, 2024

Hello, could you solve it? I have the same error
Do you have a version that I can try in my package to solve the problem at least until there is a solution?

from nestjs-typegoose.

GuillaumeGSO avatar GuillaumeGSO commented on July 17, 2024

Hi, i have a similar problem on a very simple training project.
@OoDeLally : fell free to have a look on this branch : https://github.com/GuillaumeGSO/notifications-project/tree/adding_mongodb

I've been stucked on this for hours now....
My model is NotificationData but the error keep using NotificationDataModel
@InjectModel(NotificationData)

Error: Nest can't resolve dependencies of the NotificationDataService (?). Please make sure
that the argument NotificationDataModel at index [0] is available in the AppModule context.

from nestjs-typegoose.

GuillaumeGSO avatar GuillaumeGSO commented on July 17, 2024

Thank you so much !
Just few lines and you saved my day !

from nestjs-typegoose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.