Mistral
Mistral

Reputation: 5

Nest can't resolve dependencies of the ResolutionSevice

im currently exploring nestjs and came across this error:

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

Potential solutions:

  • If ResolutionRepository is a provider, is it part of the current ResolutionService?
  • If ResolutionRepository is exported from a separate @Module, is that module imported within ResolutionService? @Module({ imports: [ /* the Module containing ResolutionRepository */ ] })

What am I doing wrong here?

resolution.module.ts

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ResolutionEntity } from './resolution.entity';
import { ResolutionService } from './resolution.service';
import { ResolutionRepository } from './resolution.repository';

@Module({
  imports: [TypeOrmModule.forFeature([ResolutionEntity])],
  providers: [ResolutionRepository, ResolutionService],
  exports: [ResolutionService],
})
export class ResolutionModule {}

resolution.service.ts

import { Injectable } from '@nestjs/common';
import { ResolutionEntity } from './resolution.entity';
import { ResolutionRepository } from './resolution.repository';

@Injectable()
export class ResolutionService {
  constructor(private readonly resolutionRepository: ResolutionRepository) {}

  async getAllByName(name: string): Promise<ResolutionEntity[]> {
    return this.resolutionRepository.getAllByName(name);
  }
}

Upvotes: 0

Views: 98

Answers (2)

DemiPixel
DemiPixel

Reputation: 1881

Instead of

TypeOrmModule.forFeature([ResolutionEntity])

Maybe you want

TypeOrmModule.forFeature([ResolutionEntity, ResolutionRepository])

Upvotes: 0

Jay McDoniel
Jay McDoniel

Reputation: 70490

You have ResolutionService in an imports array somewhere in your application. Providers never go in the imports array, only in the providers. If you need this provider in another module, the ResolutionModule should have the ResolutionService in the providers and exports arrays, and then this new module should have ResolutionModule in the imports array.

Upvotes: 1

Related Questions