3

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",
David Makogon
  • 69,407
  • 21
  • 141
  • 189
jonathan
  • 63
  • 5
  • Isn't the one that is not working missing the `@azure/cosmos` dependency? – Matias Quaranta Sep 15 '22 at 14:13
  • I tested with "@azure/cosmos": "^3.17.0" and it still not working – jonathan Sep 15 '22 at 14:26
  • can you try updating to 3.17.1 and let me know what happens – Sajeetharan Sep 15 '22 at 14:52
  • The same error Nest can't resolve dependencies of the AzureCosmosDbCoreModule – jonathan Sep 15 '22 at 17:34
  • I remember seeing this error too. Have you compared the _exact_ versions of the listed packages in both working and non-working case? You can do that by inspecting the `package-lock.json` file. – skink Sep 16 '22 at 09:04
  • 1
    The only change that I see in the package.json are the nestjs peer dependencies version 8 working and v9 non-working no more – jonathan Sep 16 '22 at 13:46
  • I have installed a blank project with version 9 and I only installed the azure module, it does not work with this version of nest I think I will create a module with the connection manually and inject it – jonathan Sep 16 '22 at 15:41
  • I see the issue with `^9.0.0` as well. After lowering version to `^8.0.0` it started working. – GThree Sep 29 '22 at 17:08
  • Having same issue, even after updating nestjs to '9.1.2' – Rodrigo Rubio Oct 04 '22 at 02:23

1 Answers1

1

I got rid of the error by adding overrides to my package.json:

"overrides": {
    "@nestjs/azure-database": {
        "@nestjs/common": "^9.1.4",
        "@nestjs/core": "^9.1.4"
    }
}

You may need to delete node_modules, package-lock.json and reinstall.

I'm not sure if anything else is broken on v9.