inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스

모듈 의존성 문제

해결된 질문

373

Haewoong Lee

작성한 질문수 12

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 {}

 

 

javascript node.js express docker tdd rest-api nestjs

답변 1

1

노원두

안녕하세요! Haewoong님!

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

image

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

그래프 ql 문서 사용할때 느낌표 남는거 어떻게 없애나요?

0

86

2

강의 전체 소스 코드를 받고싶습니다.

0

77

2

fontawesome 사용 문의

0

80

2

소스 코드 부탁드립니다~

0

87

2

깃 레포지터리 소스

0

87

2

커리큘럼12.css 정렬 에 나오는 과제 정답알고싶어요

0

74

2

10-01 Entity TypeOrmModule.forRoot 에 entities

0

89

3

강의 버전관련 문의입니다

0

104

2

Ubuntu 설치 관련

0

62

1

schema.gql 질문 드립니다.

0

51

1

서버 재실행시 Many to Many

0

102

3

input 관련 문의

0

90

2

Rest API 보다는 graphql이 주된 내용인데

0

134

2

강의 전체 소스코드 받을수있을까요?

0

156

1

도커볼륨 마운트 관련

0

127

2

findOne 타입스크립트오류

0

109

1

http => htrtps 호출 인증서 신뢰 오류

0

356

1

self-signed certificate in certificate chain 에러 발생

0

421

1

mongoose 설치 오류

0

143

1

특정 API, 특정 IP 허용 (단일경로에 CORS 활성화)

0

285

2

08-06

0

180

3

구조랑 패턴 관련해서 질문

0

126

2

mydocker

0

129

2

coolsms statuscode 2000 인데 전송안돼는 경우 확인.

0

156

1