개인공부/TIL(Today I Learned)

TIL 84일차 Error(npm install, storybook)

soon327 2021. 4. 12. 23:56

npm install 오류

code ERESOLVE 오류!

npm install시 package.json에 기록된 모듈의 버전과
로컬에 설치된 모듈의 버전이 달라서 생기는 오류인 듯하다.

오류메시지

해결

다운그레이드하여 설치해준다.

npm install --save --legacy-peer-deps

StoryBook babel-loader 오류

npx sb init 실행 후 스토리북을 실행시켰을 때, 설치되어 있는babel-loader의 버전이
storybook이 요구하는 버전보다 높아서 생기는 오류인듯 하다.

오류 메시지

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.1.0"
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:
  /home/michael/pgit/my-app/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 /home/michael/pgit/my-app/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!

해결

package.json에 다음을 추가하여 yarn이 babel-loader 8.1.0을 사용하도록 한다.

"resolutions": {
  "babel-loader": "8.1.0"
},

이후, yarn install을 실행하여 종속성을 새로 고치면 된다.