Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 compression using up to 4 threads.
Compressing objects: 100% (212/212), done.
Writing objects: 100% (213/213), 515.89 KiB | 0 bytes/s, done.
Total 213 (delta 40), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Node.js app detected
remote: 
remote: -----> Build failed
remote:  !     Two different lockfiles found: package-lock.json and 
yarn.lock
remote: 
remote:        Both npm and yarn have created lockfiles for this 
application,
remote:        but only one can be used to install dependencies. 
Installing
remote:        dependencies using the wrong package manager can 
result in missing
remote:        packages or subtle bugs in production.
remote: 
remote:        - To use npm to install your application's 
dependencies please delete
remote:          the yarn.lock file.
remote: 
remote:          $ git rm yarn.lock
remote: 
remote:        - To use yarn to install your application's 
dependences please delete
remote:          the package-lock.json file.
remote: 
remote:          $ git rm package-lock.json
remote:     
remote:        https://kb.heroku.com/why-is-my-node-js-build-
failing-because-of-conflicting-lock-files
remote: 
remote:  !     Push rejected, failed to compile Node.js app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to MyAPP.
 remote: 
 To https://git.heroku.com/MyAPP.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 
https://git.heroku.com/MyAPP.git'

I did rm and removed the yarn lock file since I use npm. Still the same error shows up. Now when I actually do rm yarn.lock I get a no entry found in the terminal. Idk why Heroku CLI insists that I still have yarn lock file in the directory.

like image 673
SeaWarrior404 Avatar asked Nov 11 '17 13:11

SeaWarrior404


People also ask

Does heroku work with yarn?

Heroku uses the lockfiles, either the package-lock. json or yarn.

What is yarn lockfile?

Whenever you run yarn (which is the equivalent of running yarn install ) upon a fresh install, a yarn. lock file is generated. It lists the versions of dependencies that are used at the time of the installation process. That means it looks into your package.

What is npm lockfile?

What's a Lock File? A lock file describes the entire dependency tree as it is resolved when created including nested dependencies with specific versions. In npm these are called package-lock. json and in yarn they are called yarn. lock .

Should I push package lock json?

json intact. It is highly recommended you commit the generated package lock to source control: this will allow anyone else on your team, your deployments, your CI/continuous integration, and anyone else who runs npm install in your package source to get the exact same dependency tree that you were developing on.


3 Answers

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
like image 100
Amera Abdallah Avatar answered Oct 19 '22 11:10

Amera Abdallah


Are you committing back to your master branch before pushing it up to Heroku?

Most often for me, problems like this arise when I make a code change and then 'git push heroku master' but my master branch has not been updated as I haven't yet committed my local changes.

Try

git commit -m 'some changes'

then

git push heroku master
like image 28
MorganIsBatman Avatar answered Oct 19 '22 09:10

MorganIsBatman


delete both yarn.lock and package-lock.json and after it:

git add --all 
git commit -a -m "Delete yarn lock and package lock"
git push 
git push heroku master

that works for me!

like image 5
matan yemini Avatar answered Oct 19 '22 09:10

matan yemini