Why is my Node.js build failing because of conflicting lock files?

Issue

Yarn and npm (versions 5+) both generate a separate file that exactly specifies dependencies, but when they are both present Heroku cannot know which package manager to use to install your dependencies

Resolution

This issue commonly occurs when your application uses npm or yarn, and someone uses the other tool to install a package and checks the resulting lock file into the repo. It could create subtle, difficult-to-debug issues in production if different versions of dependencies are installed, so it's better to resolve this up front.

To resolve this, remove the lock file from the tool that your team does not usually use and redeploy your application:

If you use npm:

git rm yarn.lock
git commit -m "Remove yarn lock file"
git push heroku master

If you use yarn:

git rm package-lock.json
git commit -m "Remove npm lock file"
git push heroku master

It may make sense to add the conflicting file to .gitignore too, to ensure that multiple people aren't checking in multiple lock files. For example, if the project has a yarn.lock file, add package-lock.json to the .gitignore.

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support