문제상황 및 에러 메시지
[Nest] 19112 - 2023. 03. 12. 오후 9:22:49 ERROR [ExceptionHandler] Nest can't resolve dependencies of the SearcherService (?). Please make sure that the argument SearcherRepositoryRepository at index [0] is available in the SearcherModule context.
Potential solutions:
- Is SearcherModule a valid NestJS module?
- If SearcherRepositoryRepository is a provider, is it part of the current SearcherModule?
- If SearcherRepositoryRepository is exported from a separate @Module, is that module imported within SearcherModule?
@Module({
imports: [ /* the Module containing SearcherRepositoryRepository */ ]
})
의존성 주입을 다시 해보기 위하여 리팩토링 하던 도중, 에러 메시지가 생겼다.
SearcherRepositoryRepository??
모양새가 좀 웃기다..
시도1
[TIL] : ERROR [ExceptionsHandler] No metadata for * was found. EntityMetadataNotFoundError: No metadata for * was found.
이 에러로 인해 고생하고 있었다. ERROR [ExceptionsHandler] No metadata for "SearcherRepository" was found. EntityMetadataNotFoundError: No metadata for "SearcherRepository" was found. SearcherRepository 파일을 찾을 수 없다는 에러이
veams.tistory.com
혹시 이전에 발생했던 에러와 동일한가 싶어서,
모듈에 작성한 코드를 잘 확인해보아도 해결되지 않은 것으로 보아 에러가 생긴 지점이 다른듯 했다.
에러메시지에 Nest can't resolve dependencies를 보아, 의존성주입하는데 뭔가 문제가 생긴것이다.
시도2
이미 커스텀리포지터리를 만든 상황이다.
searcher.service.ts 쪽에 의존성 주입 코드를 작성하는 과정에서,
이전에 잘못 작성한 의존성주입 관련 코드를 깜빡하고 지우질 않아서 이런 문제가 생겼다.
--> 이 코드에 문제가 생긴 것이다.
위 코드를 지우니 서버가 작동하다가 멈추었다.
서버가 열리다가 만다 것이다.
위 코드를 지우니 다음과 같은 문제가 다시 나타났다.
비슷한 에러메시지이다.
에러메시지
[Nest] 15580 - 2023. 03. 12. 오후 9:12:28 ERROR [ExceptionHandler] Nest can't resolve dependencies of the SearcherController (?). Please make sure that the argument SearcherServiceRepository at index [0] is available in the SearcherModule context.
Potential solutions:
- Is SearcherModule a valid NestJS module?
- If SearcherServiceRepository is a provider, is it part of the current SearcherModule?
- If SearcherServiceRepository is exported from a separate @Module, is that module imported within SearcherModule?
@Module({
imports: [ /* the Module containing SearcherServiceRepository */ ]
})
에러메시지는 좀 다르다.
SearcherServiceRepository??
이번에는 콘트롤러 쪽을 보니 잘못 쓴 위 코드가 있었다.
결과
@InjectRepository()를 지우면 잘 작동한다.
알게 된 점
의존성주입 제대로 알고 쓰자.
@InjectRepository() 데코레이터를
적절한 곳에, 적절하게 사용할 것!
잘못 쓴 것으로 이 문제가 생긴 것이다!
'개발 학습일지(TIL)' 카테고리의 다른 글
TIL : NestJS, TypeORM, EJS 검색 결과 갯수 구하기 (0) | 2023.03.22 |
---|---|
TIL : Nestjs, 특정 페이지(URL) 접근만 미들웨어 예외 처리 (0) | 2023.03.13 |
[TIL] CSS 적용이 안 되는 이유. 일부 페이지만 CSS 적용 안 되는 오류 (0) | 2023.03.11 |
[TIL] : ERROR [ExceptionsHandler] No metadata for * was found. EntityMetadataNotFoundError: No metadata for * was found. (0) | 2023.03.08 |
[TIL] : Nestjs 에서 express-ejs-layouts 사용하기 require() vs import() (0) | 2023.03.06 |
댓글