[Errors] Nest can't resolve dependencies of the UsersService (?). Please make sure that the argument UsersRepository at index [0] is available in the UsersModule context.Potential solutions:- If UsersRepository is a provider, is it part of the current U..

2021. 7. 15. 18:00Errors

반응형

Nest can't resolve dependencies of the UsersService (?). Please make sure that the argument UsersRepository at index [0] is available in the UsersModule context.

Potential solutions:
- If UsersRepository is a provider, is it part of the current UsersModule?
- If UsersRepository is exported from a separate @Module, is that module imported within UsersModule?
  @Module({
    imports: [ /* the Module containing UsersRepository */ ]
  })

 

 

Nest.js 에서 번번잖게 보는 에러(?)이다.

이유야 다양하지만, 나의 경우에 대해서 설명 해 주겠다.

 

app.module.ts

app.module.ts

다음은 user.module.ts이다.

user.module.ts

다음은 user.controller.ts 

user.controller.ts

 

다음은 CreateUserDto이다.

CreateUserDto

이제 user.service.ts이다.

user.service.ts

코드만 놓고보면 전혀 문제가 없다.

하지만 계속해서 에러메세지를 뱉어낸다.

2시간을 엄청 헤매다가 공식 문서를 보았더니, 해결책이 있었다.

 

forfeature()함수는 현재의 범위에서 레파지토리를 등록 해준다. (여기에서 범위라면 아마 해당 모듈이겠지...? 영어 해석을 잘 못 하니 잘 하시는 분들은 알아서 해석 하시길 바랍니다.)

forFeature()를 추가 해주지 않았던 것이다.

user.module.ts에 forFeature()를 추가 주었더니, 이제 정상적으로 작동을 한다.

 

user.module.ts

 

짠 이렇게 추가 해주었다.

이제 정상적으로 작동이 된다.

반응형