• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

모듈 의존성 문제

23.06.03 01:29 작성 조회수 198

0

@Module({
    imports: [
        TypeOrmModule.forFeature([Product, ProductTag, ProductCategory]),
        UserModule,
        ProductTagModule,
        ProductCategoryModule,
    ],
    providers: [
        ProductResolver,
        ProductService,
    ],
})
export class ProductModule {}

위와 같은 코드에서 ProductService의 실행에 필요한 ProductTagModule과 ProductCategoryModule를 다 import 해주었는데 계속 아래와 같은 의존성 오류가 나왔습니다.

Nest can't resolve dependencies of the ProductService (ProductRepository, ?, UserService, ProductCategoryService). Please make sure that the argument ProductTagService at index [1] is available in the ProductModule context.

Potential solutions:

- Is ProductModule a valid NestJS module?

- If ProductTagService is a provider, is it part of the current ProductModule?

- If ProductTagService is exported from a separate @Module, is that module imported within ProductModule?

@Module({

imports: [ /* the Module containing ProductTagService */ ]

})

 

그래서 아래와 같이 ProductTagService, ProductCategoryService를 임의로 providers에 넣어주면 또 실행이 됩니다. 해당 모듈을 이미 임포트 해주었는데 왜 서비스를 따로 또 주입해주어야 할까요?

@Module({
    imports: [
        TypeOrmModule.forFeature([Product, ProductTag, ProductCategory]),
        UserModule,
        ProductTagModule,
        ProductCategoryModule,
    ],
    providers: [
        ProductResolver,
        ProductService,
        ProductTagService,
        ProductCategoryService,
    ],
})
export class ProductModule {}

 

아래는 ProductTagModule과 ProductCategoryModule 코드입니다.

@Module({
    imports: [TypeOrmModule.forFeature([ProductTag])],
    providers: [ProductTagResolver, ProductTagService],
})
export class ProductTagModule {}

 

@Module({
    imports: [TypeOrmModule.forFeature([ProductCategory])],
    providers: [ProductsCategoriesResolver, ProductCategoryService],
})
export class ProductCategoryModule {}

 

 

답변 1

답변을 작성해보세요.

1

안녕하세요! Haewoong님!

모듈을 import 하기 위해선, 먼저 export로 필요한 부분을 내보내 주셔야 합니다!

image

export를 추가하여 다시 한 번 시도해 보세요!^^