#SequelizeModule.forRootAsync() dependency issue

1 messages · Page 1 of 1 (latest)

wide geyser
#

After adding the configuration module to better handle different environments for my application...

I get an error:

ERROR [ExceptionHandler] Nest can't resolve dependencies of the ProductRepository (?). Please make sure that the argument Sequelize at index [0] is available in the SequelizeModule context.

Potential solutions:
- Is SequelizeModule a valid NestJS module?
- If Sequelize is a provider, is it part of the current SequelizeModule?
- If Sequelize is exported from a separate @Module, is that module imported within SequelizeModule?
  @Module({
    imports: [ /* the Module containing Sequelize */ ]
  })

Here is my app module imports:

@Module({
  imports: [
    SequelizeModule.forRootAsync({
      imports: [ConfigModule],
      name: "pros_and_contractors",
      useFactory: (configService: ConfigService) => ({
        dialect: "postgres",
        host: configService.get<string>("database.host"),
        port: configService.get<number>("database.port"),
        username: configService.get<string>("database.username"),
        password: configService.get<string>("database.password"),
        database: configService.get<string>("database.database"),
        synchronize: true, // consider changing
        autoLoadModels: true, //consider changing
        models: [],
      }),
      inject: [ConfigService],
    }),
    ConfigModule.forRoot({
      envFilePath: ".env",
      isGlobal: true,
      load: [configuration],
    }),
    AuthModule,
    UserModule,
    ListingModule,
    ContractorModule,
    SupplierModule,
    ProductModule,
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}
vivid path
#

can youn run npx nest info

#

also, please don't use the NestJS Devtools tag unless your question is related with NestJS Devtools tool 🙂

wide geyser
#
[System Information]
OS Version     : {REMOVED}
NodeJS Version : v16.15.1
NPM Version    : 8.19.2 

[Nest CLI]
Nest CLI Version : 9.2.0 

[Nest Platform Information]
platform-express version : 9.3.9
schematics version       : 9.0.4
sequelize version        : 9.0.0
passport version         : 9.0.3
swagger version          : 6.2.1
testing version          : 9.3.9
common version           : 9.3.9
config version           : 2.3.4
core version             : 9.3.9
jwt version              : 10.1.0
cli version              : 9.2.0
vivid path
#

did you have Sequelize.forFeature somewhere?

wide geyser
#

yes, in all the modules Im importing models into

#

for example

#

@Module({
  imports: [SequelizeModule.forFeature([Listing])],
  controllers: [ListingController],
  providers: [ListingService],
})
export class ListingModule {}
#

oh but not Sequelize.forFeature

#

that im not seeing anywhere at the moment

vivid path
#

so you have that name in your forRoot but you didn't define the same connection name in the forFeature

#

I guess that's why

wide geyser
#

I assume the name is the database name?

vivid path
#

nop

#

the connection name

wide geyser
#

oh so postgres?

vivid path
#

as you have in SequelizeModule.forRootAsync(

#

see your code

wide geyser
#

oh so I need to add name to this as well?

@Module({
  imports: [SequelizeModule.forFeature([Listing])],
  controllers: [ListingController],
  providers: [ListingService],
})
export class ListingModule {}
vivid path
#

yes, unless you want to use the default connection name

wide geyser
# vivid path

yah that was added because I read it fixed some persons issue

#

ahh when I remove name, its unable to connect to database now

#

so it was right

vivid path
#

feel free to try to improve the error message
it's quiet confusing

wide geyser
#
[Nest] 22287  - 18/07/2023, 16:16:13   ERROR [ExceptionHandler] Nest can't resolve dependencies of the ProductRepository (?). Please make sure that the argument Sequelize at index [0] is available in the SequelizeModule context.

Potential solutions:
- Is SequelizeModule a valid NestJS module?
- If Sequelize is a provider, is it part of the current SequelizeModule?
- If Sequelize is exported from a separate @Module, is that module imported within SequelizeModule?
  @Module({
    imports: [ /* the Module containing Sequelize */ ]
  })

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

Potential solutions:
- Is SequelizeModule a valid NestJS module?
- If Sequelize is a provider, is it part of the current SequelizeModule?
- If Sequelize is exported from a separate @Module, is that module imported within SequelizeModule?
  @Module({
    imports: [ /* the Module containing Sequelize */ ]
  })```
#

thats the full error, but I removed the error stack

#

because it has my computer info on it

wide geyser
#

dont have time for that right now

#

also im not sure what you mean by adding it to forFeatureit doesnt accept name

#

@vivid path reading through this, doesnt help either

vivid path
#

read the TS docs

#

isn't in the docs site but you can find it out using the editor's intelisense
it's the second arg of forFeature()