Search code examples
javascriptgitherokucreate-react-app

Heroku "failed to push some refs" when trying to push React app


Going by this: https://dev.to/smithmanny/deploy-your-react-app-to-heroku-2b6f, I am trying to deploy a simple react app out of the box from create-react-app to Heroku.

npx create-react-app my-app
cd my-app
npm install

Then add these to package.json:

"engines": {
    "npm": "6.12.0",
    "node": "10.16.3"
},

Then:

heroku login blah...
git init
git add .
git commit -m "initial commit"
heroku create
git remote add heroku https://git.heroku.com/damp-spire-48480.git (auto-generated name of app)
git push heroku master

Then I get this:

Enumerating objects: 27666, done.
Counting objects: 100% (27666/27666), done.
Delta compression using up to 8 threads
Compressing objects: 100% (20069/20069), done.
Writing objects: 100% (27666/27666), 24.31 MiB | 362.00 KiB/s, done.
Total 27666 (delta 5987), reused 27666 (delta 5987)
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://help.heroku.com/0KU2EM53
remote: 
remote:  !     Push rejected, failed to compile Node.js app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to damp-spire-48480.
remote: 
To https://git.heroku.com/damp-spire-48480.git
 ! [remote rejected]   master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/damp-spire-48480.git'

I've looked at a few SO pages now, and so far not seeing a solution. I should not that I've had a few apps and remotes up there, but I think I've removed all app and remotes, and tried to start from scratch... Unless there's something else to clean up...

I tried this one: Push to Heroku denied - "failed to push some refs to 'heroku". So I tried: git push heroku master:master and git push heroku HEAD:master and got the same result each time.


Solution

  • If there was one in there, and you remove it later, then it still fails.

    It should not, if you remove it and commit, recording the deletion:

    As explained in Heroku page "Why is my Node.js build failing because of conflicting lock files?"

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

    And/or

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