본문 바로가기

신나는 오류해결파티!!!

[jest & webpack] 에러 몇가지 "jest-environment-jsdom" is no longer shipped by default, Cannot find module, Configuration error: Could not locate module mapped as...

 

결론 : 설치 추가 필요 

npm install -D jest-environment-jsdom
npm install -D @testing-library/react
npm install -D @testing-library/jest-dom

 

 

1) 

 As of Jest 28 "jest-environment-jsdom" is no longer shipped by default, make sure to install it separately.

 


 

 

 

에러의 원인  

module이 설치되어있지 않았음

 

 

에러 해결

jest-environment-jsdom 설치

 

npm install -D jest-environment-jsdom

 

 

 

 

 

 

2) 

Cannot find module '@testing-library/jest-dom'

 

 

에러의 원인  

module이 설치되어있지 않았음

 

에러 해결

npm i @testing-library/react

 

 

 

3)

Cannot find module '@testing-library/react' 

 

 

에러의 원인  

module이 설치되어있지 않았음

 

 

에러 해결

npm i @testing-library/jest-dom

 

 

 

 

 

4) 


Configuration error: Could not locate module  mapped as:  Please check your configuration for these entries:    {      "moduleNameMapper": {        "/\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$/":

 


 

 

 

에러의 원인  

경로 잘못 설정

해당 에러의 원인은 typescript에서 module을 declare해주지 않았던 이유였음

먼저 원하는 폴더 경로에 types.d.ts파일을 만들어 주고 module을 declare해준 뒤 

해당 declare한 파일의 경로를 moduleNameMapper에 설정해 줄 것

 

"moduleNameMapper": {
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/src/typings/types.d.ts",
      "\\.(css|less)$": "<rootDir>/src/typings/types.d.ts",
      "src/(.*)": "<rootDir>/$1"
    }

 

나의 경우 types.d.ts파일을 src/typings에 declare했기 때문에 해당 경로로 수정 해 준 것.

 

 

해결!!!