Two different lockfiles found: package-lock.json and yarn.lockがherokuデプロイ時に出たら?
結論
yarnとnpmロックファイルが同時に存在すると、herokuは依存関係に用いるパッケージマネージャを認識することができないために発生するエラー。 yarnかnpmのどちらか使っていない方のロックファイルを削除しましょう。
- npmを使用するならyarnロックファイルを削除します。
git rm yarn.lock git commit -m "Remove yarn lock file" git push heroku master
- yarnを使用するならnpmのロックファイルを削除します。
git rm package-lock.json git commit -m "Remove npm lock file" git push heroku master
発生事例
herokuにauto deployをした時に以下のエラーが発生しました。
-----> 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://kb.heroku.com/why-is-my-node-js-build-failing-because-of-conflicting-lock-files ! Push rejected, failed to compile Node.js app. ! Push failed
jsのパッケージ管理にnpmとyarnを使っていたことが原因のようです。 herokuのhelpに解決策が載っていたのですぐに対応することができました。
もうちょい詳しく
例えば、2つのロックファイルに同じライブラリが異なるバージョンで設定されていた時にエラーが発生する可能性があります。 その問題を回避するため、herokuはあらかじめロックファイルを1つに絞り対策を講じている、ということです。
参考
Why is my Node.js build failing because of conflicting lock files? - Heroku Help