I Learned/TIL
[TIL] Nest 중복 호출 오류, Node process.cwd()와 __dirname의 차이
beeimp
2022. 7. 13. 23:27
[TIL] Nest 중복 호출 오류, Node process.cwd()
와 __dirname
의 차이
날짜
- 2022.07.13.
목표
- Nest.js 학습
내용
Nest.js - @**InjectConnection
** 중복 호출 오류
오류 메세지
ERROR [ExceptionHandler] Nest can't resolve dependencies of the AuthService (JwtService, ?, UsernameConnection). Please make sure that the argument UserConnection at index [1] is available in the AuthModule context. Potential solutions: - If UserConnection is a provider, is it part of the current AuthModule? - If UserConnection is exported from a separate @Module, is that module imported within AuthModule? @Module({ imports: [ /* the Module containing UserConnection */ ] })
원인
@**InjectConnection
** 가 두번 선언되어서 오류 발생export class AuthService { constructor( private jwtService: JwtService, **@InjectConnection(User.name) private userModel: Model<User>, @InjectConnection(Username.name) private usernameModel: Model<Username>,** ) {} ... }
해결
export class AuthService { userModel: Model<UserDocument>; usernameModel: Model<UsernameDocument>; constructor( private jwtService: JwtService, **@InjectConnection() private readonly mongooseConnection: Connection,** ) { this.userModel = mongooseConnection.model(User.name); this.usernameModel = mongooseConnection.model(Username.name); } ... }
Node.js - process.cwd()
와 __dirname
의 차이
process.cwd()
- 전역 객체의 메소드
- 프로세스의 현재 작업 디렉토리를 문자열 값으로 리턴
__dirname
- 현재 스크립트의 디렉토리 이름
- 전역이 아니라 각 모듈에 대해 로컬을 문자열 값으로 리턴
결론
- 오류의 원인을 정확히는 모르겠지만 잘 해결되었습니다.