nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.66k stars 7.63k forks source link

Nest can't resolve dependencies for the CounterMetric used in Service class #3817

Closed RakhiSehrawat closed 4 years ago

RakhiSehrawat commented 4 years ago

Bug Report

[Nest] 26184 - 01/14/2020, 3:24:49 PM [ExceptionHandler] Nest can't resolve dependencies of the TestService (ControlAndReportApiService, ?). Please make sure that the argument at index [1] is available in the TestModule context. +2ms Error: Nest can't resolve dependencies of the TestService (ControlAndReportApiService, ?). Please make sure that the argument at index [1] is available in the ControlAndReportModule context. at Injector.lookupComponentInExports (D:\nestjs-prom-master\provision-alerter\node_modules\@nestjs\core\injector\injector.js:183:19) at processTicksAndRejections (internal/process/task_queues.js:93:5) at async Injector.resolveComponentInstance (D:\nestjs-prom-master\provision-alerter\node_modules\@nestjs\core\injector\injector.js:143:33) at async resolveParam (D:\nestjs-prom-master\provision-alerter\node_modules\@nestjs\core\injector\injector.js:96:38) at async Promise.all (index 1) at async Injector.resolveConstructorParams (D:\nestjs-prom-master\provision-alerter\node_modules\@nestjs\core\injector\injector.js:112:27) at async Injector.loadInstance (D:\nestjs-prom-master\provision-alerter\node_modules\@nestjs\core\injector\injector.js:78:9)
at async Injector.loadProvider (D:\nestjs-prom-master\provision-alerter\node_modules\@nestjs\core\injector\injector.js:35:9)
at async Promise.all (index 4) at async InstanceLoader.createInstancesOfProviders (D:\nestjs-prom-master\provision-alerter\node_modules\@nestjs\core\injector\instance-loader.js:41:9)

Current behavior

Whenever I do npm run start it gives me the above error and I am using the below code.

I followed the ReadMe instructions to used the digikare/nestjs-prom library into our project. I added the following: In app.module.ts : @Module({ imports: [ PromModule.forRoot({ defaultLabels: { app: 'provision_alerter', }, customUrl: 'order/metrics' }),]

In test.module.ts:

@Module({ imports:[ PromModule.forMetrics([ { type: MetricType.Counter, configuration: { name: 'index_counter', help: 'get count of test orders', } }]), ], providers:[TestService, ControlAndReportApiService], controllers:[TestController] }) export class TestModule{}

In test.service.ts:

constructor(private readonly controlAndReportApiService: ControlAndReportApiService, @InjectCounterMetric('index_counter') private readonly _counterMetric: CounterMetric, ) { }

async findTestOrders(): Promise<Order[]> {

  const testOrders: Order[] = await getTestOrders();

    this._counterMetric.inc(testOrders.length, new Date());

    return testOrders;

}

Can someone please help me in case I am missing out something here?

kamilmysliwiec commented 4 years ago

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.