Guide to setting up Cosmos DB database connection using NestJS version 9.0.0

I'm encountering issues when attempting to include the Cosmos DB connection module in nestjs v9, as I'm facing dependency errors.

Nest is unable to resolve the dependencies of the AzureCosmosDbCoreModule (COSMOS_DB_CONNECTION_NAME, ?). Please ensure that the argument ModuleRef at index [1] is accessible within the AzureCosmosDbCoreModule context. 

    Possible remedies:
    - If ModuleRef is a provider, is it included in the current AzureCosmosDbCoreModule?
    - If ModuleRef is exported from another @Module, have you imported that module into AzureCosmosDbCoreModule?
      @Module({
        imports: [ /* the Module containing ModuleRef */ ]
      })

When downgrading nestjs to version 8, the connection module functions as expected. The same code is used in 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 information (not working): 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 information (working): Node v16.16.0

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

Answer №1

To resolve the issue, I successfully fixed it by making modifications in my package.json:

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

If needed, consider removing node_modules, package-lock.json and then reinstalling.

It's uncertain if there are any other issues present in version 9.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

type Y does not contain property X

When I encounter this error message: The property 'module' is missing in the type 'Menu'. The property 'parentId' is not found in the type 'Menu'. the code snippet triggering it appears like this: private menus: ...

The [image link] in the NextJS image was loaded in advance using link preload, but it was not utilized within a short time after the window finished loading

While working on my blog website with NextJS, I encountered a warning in the console related to using next/image: The resource http://localhost:3000/_next/image... was preloaded using link preload but not used within a few seconds from the window's lo ...

NextImage encountering issues in Internet Explorer 11

In my TypeScript setup, here is a snippet from my package.json file: "dependencies": { "@tailwindcss/typography": "^0.4.1", "@webcomponents/shadydom": "^1.7.4", "cookie": "^0.4.1", " ...

Tips for submitting a request following a change in the variable

I am in the process of developing a React application and I have implemented Auth0 for authentication. My goal is to initiate an HTTP request upon page refresh, but only if the variable isLoading is false. This way, I can access the user object once the ...

What is the best way to send an object to an Angular form?

I am facing an issue with my Spring entity, Agent, which includes an Agency object. When adding a new agent, I need to pass the agency as an object in the Angular form. While the backend code is functioning correctly, I am struggling to figure out how to p ...

Develop a new flow by generating string literals as types from existing types

I'm running into a situation where my code snippet works perfectly in TS, but encounters errors in flow. Is there a workaround to make it function correctly in flow as well? type field = 'me' | 'you' type fieldWithKeyword = `${fiel ...

Rendering a Nativescript component once the page has been fully loaded

I'm currently working on integrating the WikitudeArchitectView into my TypeScript code. I've successfully registered the element in the main.ts TypeScript file: var architectView = require("nativescript-wikitudearchitectview"); registerElement ...

Tips for inserting a component into a div selector using Angular 2

Could someone please help me figure out how to inject a component into a div selector using a class or id? I'm familiar with injecting components into other components, but not sure how to do it specifically within a div. Any guidance would be greatly ...

Angular Typescript filter function returning an empty arrayIn an Angular project, a

I have a filtering function in Angular that is returning an empty array. Despite trying similar solutions from previous questions, the issue persists. The function itself appears to be correct. Any assistance would be greatly appreciated. gifts represents ...

When parameters are added to one route, all other routes cease to function properly

After I added a parameter to one of the routes, all the other routes stopped rendering correctly (i.e., router-view is not working at all). The route /download/:id works as expected. Am I missing something in the setup? I tried leaving and removing the /do ...

Refreshing Angular 9 component elements when data is updated

Currently, I am working with Angular 9 and facing an issue where the data of a menu item does not dynamically change when a user logs in. The problem arises because the menu loads along with the home page initially, causing the changes in data to not be re ...

Combine the node_modules for the browser and preserve the integrity of the "app.js" file

When creating a js file that utilizes the npm node module greetings, I include it in my app.js for use in the browser using browserify: https://i.stack.imgur.com/r2WSh.jpg The structure of my index.html is as follows: https://i.stack.imgur.com/ggzMY.jpg ...

What is the best way to test for errors thrown by async functions using chai or chai-as-promised?

Below is the function in question: async foo() : Promise<Object> { if(...) throw new Error } I'm wondering how I should go about testing whether the error is thrown. This is my current approach: it("checking for thrown error", asy ...

Can you reach a screen prior to the stack navigator being established?

I'm diving into the world of React and decided to use Expo for building an app. I went with the TypeScript setup that comes with pre-implemented tabs and navigator by running "expo init newApp". Now, I just need a transition screen to display briefly ...

What is the best way to ensure type safety in a Promise using Typescript?

It seems that Promises in Typescript can be type-unsafe. This simple example demonstrates that the resolve function accepts undefined, while Promise.then infers the argument to be non-undefined: function f() { return new Promise<number>((resolve) ...

Error encountered while transforming object due to index type mismatch

I am attempting to change the values of an object, which consist of arrays with numbers as keys, to their respective array lengths. However, I received a type error that says 'Element implicity has any type because a string element cannot be used to ...

Adding existing tags to Select2 in Angular2 can be accomplished by following these steps:

HTML: <select data-placeholder="Skill List" style="width:100%;" class="chzn-select form-control" multiple="multiple"> <option *ngFor="#skill of allSkills" [ngValue]="skill">{{skill}} </option> </select> TS: allSkills = [& ...

Customizable mongoDB database collection

Is there a more efficient way to make calls to different collections based on a function parameter? I'm exploring the possibility and if it's not feasible, I'll handle it case by case. Currently, I have this code and the goal is to have a u ...

Utilize the Lifecycle Interface within Angular 2 framework for enhanced application development

Can you explain the impact of this rule? "use-lifecycle-interface": true, ...

Click function for mat-step event handler

Is it feasible to create a click event for the mat-step button? I want to be able to add a (click) event for each mat-step button that triggers a method. Essentially, I am looking to make the mat-step button function like a regular button. You can find mo ...