由于Yarn和npm锁定文件冲突导致Heroku构建失败

问题描述:

我试图使用CLI在Heroku上部署React Web应用程序。由于Yarn和npm锁定文件冲突导致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' 

我做RM和去除纱线锁文件,因为我使用NPM:然而,当我运行,

 git push heroku master 

从我的项目文件夹,它抛出一个错误。仍然出现同样的错误。现在,当我真正做到yarn.lock时,我在终端中找不到任何条目。 Idk为什么Heroku CLI坚持我目录中仍然有纱线锁定文件。

在将其推向Heroku之前,您是否承诺回到主分支?

对我来说,最常见的问题是当我更改代码然后'git push heroku master'但我的主分支还没有更新,因为我还没有提交我的本地更改。

尝试

git commit -m 'some changes' 

然后

git push heroku master 
+0

为什么git-push会关心未提交的更改?我认为它应该有或没有**“一些改变”。** – joshuamabina

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