WEB/React
Heroku 배포 중 Node.js 빌드 오류(yarn.lock , package-lock.json 충돌 문제) 해결
minsung521
2021. 8. 9. 00:47
React 앱을 만들고 Heroku에 배포하던 중 오류가 생겼다.
git push heroku master 명령어로 할 때마다 아래와 같은 빌드 실패가 발생했는데
npm run build 로 따로 빌드해보면 또 문제없이 돌아가서 골머리를 앓았다.
-터미널
-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
-----> Node.js app detected
-----> Build failed
! Two different lockfiles found: package-lock.json and yarn.lock
Both npm and yarn have created lockfiles for this application,
but only one can be used to install dependencies. Installing
dependencies using the wrong package manager can result in missing
packages or subtle bugs in production.
- To use npm to install your application's dependencies please delete
the yarn.lock file.
$ git rm yarn.lock
- To use yarn to install your application's dependences please delete
the package-lock.json file.
$ git rm package-lock.json
https://help.heroku.com/0KU2EM53
! Push rejected, failed to compile Node.js app.
! Push failed
-heroku build log
다른 리액트 앱에서도 동일한 오류가 발생했었는데, 구글링 끝에 해결책을 찾아낼 수 있었다.
Heroku build failing due to Yarn and npm lockfile conflict
I'm trying to deploy a React Web app on Heroku using the Heroku CLI. However when I run, git push heroku master from my project folder it throws an error as: Counting objects: 213, done. Delta
stackoverflow.com
해답은 위의 스택오버플로우 글에서 찾아낼 수 있었다.
yarn 과 npm 의 의존성 관리파일인 yarn.lock 과 package-lock.json 파일이 충돌해서 빌드 실패가 떳던 것이다.
전에는 npm 만 쓰다가 최근에 yarn 을 써보기 시작했는데 이 때문에 문제가 생겼던 것 같다.
해결방법은 다음과 같다.
npm 사용시 :
git rm yarn.lock
git commit -m "Remove yarn lock file"
git push heroku master
yarn 사용시 :
git rm package-lock.json
git commit -m "Remove npm lock file"
git push heroku master