How to establish Cosmos DB database connection with nestjs v^9.0.0

Viewed 51

I'm trying to import the Cosmos DB connection module in nestjs v9, but I'm getting dependencies errors.

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:
    - 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 */ ]
      })

If I lower nestjs to version 8, the connection module works fine, I use this same code with both projects:

import { AzureCosmosDbModule } from '@nestjs/azure-database';
import { Module } from '@nestjs/common'; 
import { AppConfigModule } from '../shared/config/app-config.module'; 
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [
    AppConfigModule, 
    AzureCosmosDbModule.forRootAsync({
      imports: [AppConfigModule],
      useFactory: async (cfg: AppConfigModule) => ({
        endpoint: cfg.get<string>('AZURE_COSMOS_DB_ENDPOINT'),
        dbName: cfg.get<string>('AZURE_COSMOS_DB_TEST_NAME'),
        key: cfg.get<string>('AZURE_COSMOS_DB_KEY'),
      }),
      inject: [AppConfigModule],
    }), 
  ],
  controllers: [AppController],
  providers: [AppService],
})
 
export class AppModule {}

project info (don't work): Node v16.16.0

    "@azure/cosmos": "^3.17.0", 
    "@nestjs/azure-database": "^2.3.0",
    "@nestjs/common": "^9.0.0", 
    "@nestjs/core": "^9.0.0", 

project info (works): Node v16.16.0

    "@nestjs/azure-database": "^2.3.0",
    "@nestjs/common": "^8.0.0",
    "@nestjs/core": "^8.0.0",
0 Answers
Related