관리 메뉴

솜씨좋은장씨

[React] yarn start 시 babel-loader 오류 해결 방법 본문

Programming/React

[React] yarn start 시 babel-loader 오류 해결 방법

솜씨좋은장씨 2021. 7. 2. 02:16
728x90
반응형

리액트 앱의 코드를 수정하고 잘 수정되었는지 

$ yarn start

위의 명령어를 통해 실행해보았는데

yarn run v1.22.0
$ 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:

  "babel-loader": "8.0.5"

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

  /Users/donghyunjang/ReactHome/react-study-first-time/node_modules/babel-loader (version: 8.2.2) 

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 "babel-loader" 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 /Users/donghyunjang/ReactHome/react-study-first-time/node_modules/babel-loader is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

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

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.

위처럼 오류가 발생했습니다.

 

이는 package.json에 입력한 babel-loader의 버전과 create-react-app의 babel-loader 과 충돌하여 그렇습니다.

 

해결하는 방법은 사실 오류 메세지를 잘 보면 나와있습니다.

1. 해당 사항을 무시하고 넘어가는 방법

먼저 프로젝트 가장 상위 디렉토리로 이동하고 .env 파일을 만들어 줍니다.

$ cd [프로젝트 최상단 디렉토리]
$ vi .env

그리고 그 안에

SKIP_PREFLIGHT_CHECK = true

위의 내용을 입력하고 저장한 다음 다시

$ yarn start

위의 명령어로 실행해보면!

제대로 동작하는 것을 볼 수 있습니다.

 

추후에 두번째 방법인 재설치 방법을 정리해보고자 합니다.

 

읽어주셔서 감사합니다.

Comments