【问题标题】:Heroku build failing due to Yarn and npm lockfile conflict由于 Yarn 和 npm 锁定文件冲突,Heroku 构建失败
【发布时间】:2018-04-24 14:17:17
【问题描述】:

我正在尝试使用 Heroku CLI 在 Heroku 上部署一个 React Web 应用程序。但是,当我跑步时,

git push heroku 大师

从我的项目文件夹中它会引​​发错误:

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'

自从我使用 npm 以来,我做了 rm 并删除了 yarn lock 文件。仍然出现相同的错误。现在,当我实际执行rm yarn.lock 时,我在终端中找不到任何条目。我想知道为什么 Heroku CLI 坚持我的目录中仍然有纱线锁定文件。

【问题讨论】:

    标签: node.js heroku server package-managers yarnpkg


    【解决方案1】:

    在将其推送到 Heroku 之前,您是否会提交回您的 master 分支?

    对我来说,最常见的情况是,当我进行代码更改然后 'git push heroku master' 但我的 master 分支尚未更新,因为我尚未提交本地更改。

    试试

    git commit -m 'some changes'
    

    然后

    git push heroku master
    

    【讨论】:

    • 为什么 git-push 应该关心未提交的更改?我认为它应该有或没有“一些变化”。
    • 这有帮助,谢谢
    【解决方案2】:

    如果你使用npm

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

    如果你使用yarn

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

    【讨论】:

    • 基于原始问题,这是最佳答案!
    • 这必须标记为问题的正确答案。
    【解决方案3】:

    我有同样的问题,但上述建议没有帮助。我所做的是删除 yarn.lock (git rm yarn.lock),错误消失了。

    【讨论】:

      【解决方案4】:

      删除 yarn.lock 和 package-lock.json 及其后:

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

      这对我有用!

      【讨论】:

        【解决方案5】:

        我遇到了同样的问题,但在我的情况下,我正在推送包含 package-lock.json 和 yarn.lock 的 master 分支。我使用命令git push heroku branch-name:master 解决了这个问题。

        【讨论】:

          【解决方案6】:

          如果您使用 npm,请按照以下说明操作:

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

          【讨论】:

            【解决方案7】:

            有同样的问题。不确定在部署到 heroku 时如何重新创建包锁,但这似乎正在发生。尝试创建一个 .npmrc 文件并添加 package-lock=false 这解决了我的问题。

            【讨论】:

              【解决方案8】:

              还要检查是否需要构建包来部署到 heroku。

              例如对于流星,您需要添加一个构建包

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

              如果您对该 git 有多个应用程序,请确保将 --app foobar 作为您的应用程序名称添加到您的 heroku 命令中

              【讨论】:

                【解决方案9】:

                就我而言,我必须检查主分支并运行 git push heroku main。 这解决了我的问题

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 2021-06-29
                  • 1970-01-01
                  • 1970-01-01
                  • 2015-04-10
                  • 1970-01-01
                  • 2021-10-14
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多