프론트 개발 블로그

[Error] create-react-app / jest 설치 후 발생하는 에러 본문

React

[Error] create-react-app / jest 설치 후 발생하는 에러

maybe.b50 2020. 10. 14. 13:54

jest 를 설치 후 npm start 혹은 yarn start 로 리액트를 브라우저에 띄우려고 할 때 아래와 같이 에러가 발생한다.

 

프로젝트 종속성 트리에 문제로 Create React App 의 버그는 아니고 앱에서 수정해야 한다고 나왔다. 

해당 매뉴얼 대로 확인해보니 Create React App 으로 리액트를 설치 했을 때

react-scripts 패키지에 jest가 이미 설치되어 있어서 에러가 나고 있었다.

yarn run v1.22.1
$ react-scripts start

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:     

  "jest": "24.9.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of jest was detected higher up in the tree:

  C:\Users\work\clone-coding-react\movie_app_clone_2020\node_modules\jest (version: 26.5.3)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "jest" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if C:\Users\work\clone-coding-react\movie_app_clone_2020\node_modules\jest is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls jest in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed jest.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

 

github.com/facebook/create-react-app/blob/master/CHANGELOG-0.x.md#migrating-from-023-to-030

 

facebook/create-react-app

Set up a modern web app by running one command. Contribute to facebook/create-react-app development by creating an account on GitHub.

github.com

 

해결 방법

기존에 설치한 jest 패키지는 삭제시킨 뒤  package.json 파일에서 아래와 같이 test 설정을 해주면 된다. 

 // ...
  "scripts": {
    // ...
    "test": "react-scripts test --env=jsdom"
  }

 

 

반응형