본문 바로가기

Backend/NestJS

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

문제 상황 

$ nest g resource Users

위의 명령어를 터미널로 입력했는데 intelliJ 터미널에서 계속 아래와 같은 에러가 출력되었다. 

 

 

 

Mac Terminal에서는 아래와 같이 에러가 출력되어 중복 이슈인가?싶어서 tsconfig.json의 

"skipLibCheck": true,

를 확인했는데도 true로 설정이 되어있어서 뭐지 싶었다. 

문제 해결 

app.module.ts 부분에서 providers 부분에서 

AppService는 등록이 되어있으나 UsersService 등록이 되어있지 않았다. 

-> 만든 모듈은 모두 app.module.ts에 모두 등록을 해주어야 한다.

 

근데 의문. 

UserController는 controllers에 자동으로 등록이 되어있었는데 

왜 providers - UsersService는 모듈 등록이 되어있지 않았던걸까?