Heroku build failing due to Yarn and npm lockfile conflict

爷,独闯天下 提交于 2019-12-22 05:41:43

问题


Im trying to deploy React Web app on Heroku using the 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.


回答1:


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



回答2:


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



回答3:


I had the same problem, but the above suggestions didn't help. What I did was to delete yarn.lock (git rm yarn.lock) and the error was gone.




回答4:


If you use npm please follow this :

rm yarn.lock
git add .
git commit -m 'remove yarn.lock file'
git push origin
git push heroku origin



回答5:


Had the same issue. Not sure how package-lock is being recreated upon deploying to heroku but thats what seems to be happening. Try creating a .npmrc file and adding package-lock=false This fixed the issue for me.




回答6:


Also check if you need a buildpack for deploying to heroku.

For example for meteor you need to add a buildpack

heroku buildpacks:set https://github.com/AdmitHub/meteor-buildpack-horse.git

if you have multiple apps for that git make sure to add --app foobar as your app name to your heroku command




回答7:


I had the same issue, but in my case I was pushing the master branch which contained both package-lock.json and yarn.lock. I fixed this by using the command git push heroku branch-name:master.



来源:https://stackoverflow.com/questions/47238241/heroku-build-failing-due-to-yarn-and-npm-lockfile-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!