NestJS에서 test 코드를 작성하고, npm test로 유닛 테스트를 진행하였는데 다음과 같이 "Cannot find module 'src/common/typeorm.entity' from 'user/user.entity.ts'"에러가 뜨면서 Failed가 발생하였다.
Cannot find module ~ from ~ 인 import 에러 형식
원인은 package.json에 jest 관련 moduleNameMapper가 빠져있어서 test를 할 때 import의 from의 위치를 프로젝트 디렉토리인 root로 지정되어 발생된 일이었다.
NestJS Test 실행 시, jest가 module을 못 찾는 경우
NestJS에서 test 코드를 작성하고, npm test로 유닛 테스트를 진행하였는데 다음과 같이 "Cannot find module 'src/common/typeorm.entity' from 'user/user.entity.ts'"에러가 뜨면서 Failed가 발생하였다.
원인은 package.json에 jest 관련 moduleNameMapper가 빠져있어서 test를 할 때 import의 from의 위치를 프로젝트 디렉토리인 root로 지정되어 발생된 일이었다.
위와 같이 package.json의 "jest" 부분에 moduleNameMapper 설정을 src 디렉토리로 설정해주면 된다.
참고) https://stackoverflow.com/questions/63865678/nestjs-test-suite-failed-to-run-cannot-find-module-src-article-article-entity
NestJS - Test suite failed to run Cannot find module 'src/article/article.entity' from 'comment/comment.entity.ts'
i need help with nestjs and jest testing. I am new to NestJS and i got stuck on Cannot find module error when i run tests. I am trying to test my service and when i run tests i have received error
stackoverflow.com
'개발 > NestJS' 카테고리의 다른 글