【问题标题】:Unable to update composer无法更新作曲家
【发布时间】:2021-12-16 14:16:15
【问题描述】:

我用 Symfony5 开发了一个应用程序并尝试在 Heroku 上部署,但在部署时出错。这是构建日志:


 WARNING: Your 'composer.lock' is out of date!    
 The 'composer.lock' file in your project is not up to date with
 the main 'composer.json' file. This may result in installation
 of incorrect packages or package versions.    
 The lock file is required in order to guarantee reliable and
 reproducible installation of dependencies across systems and
deploys. It must always be kept in sync with 'composer.json'.

Whenever you change 'composer.json', ensure that you perform
the following steps locally on your computer:
1) run 'composer update'
2) add all changes using 'git add composer.json composer.lock'
3) commit using 'git commit'

Ensure that you updated the lock file correctly, and that you ran 'git add' on both files, before deploying again.
Please remember to always keep your 'composer.lock' updated in lockstep with 'composer.json' to avoid common problems related to dependencies during collaboration and deployment.

-----> Installing dependencies...
       Composer version 2.1.9 2021-10-05 09:47:38
       Installing dependencies from lock file
       Verifying lock file contents can be installed on current platform.
       Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.

WARNING: An error occurred during a database connection or query
ERROR: Dependency installation failed
 The 'composer install' process failed with an error. The cause may be the download or installation of packages, or a pre- or post-install hook (e.g. a 'post-install-cmd' item in 'scripts') in your 'composer.json'.    

Typical error cases are out-of-date or missing parts of code, timeouts when making external connections, or memory limits. Check the above error output closely to determine the cause of the problem, ensure the code you're pushing is functioning properly, and that all local changes are committed correctly.
    
REMINDER: the following warnings were emitted during the build;
check the details above, as they may be related to this error:
- Your 'composer.lock' is out of date!
- An error occurred during a database connection or query
Push rejected, failed to compile PHP app.
Push failed

所以我尝试在终端中运行 composer update 但收到此错误消息:

Loading composer repositories with package information
Restricting packages listed in "symfony/symfony" to "5.3.*"
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires phpunit/phpunit 4.7.7 -> satisfiable by phpunit/phpunit[4.7.7].
    - phpunit/phpunit 4.7.7 requires symfony/yaml ~2.1|~3.0 -> found symfony/yaml[v2.1.0, ..., v2.8.52, v3.0.0, ..., v3.4.47] but it conflicts with your root composer.json require (5.3.*).
  Problem 2
    - Root composer.json requires phpspec/phpspec 2.2.1 -> satisfiable by phpspec/phpspec[2.2.1].
    - phpspec/phpspec 2.2.1 requires symfony/console ~2.3 -> found symfony/console[v2.3.0, ..., v2.8.52] but it conflicts with your root composer.json require (5.3.*).

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

我了解 phpunit、composer.json 和 .lock 文件存在冲突,但找不到解决方法。请问有什么帮助吗?

【问题讨论】:

  • 我已经删除了不相关的标签——即使您只是在部署到另一台服务器时才看到这一点,该部署本身也不会对这个错误负责。出于好奇:您是如何安装任何软件包以达到这种不一致的状态的?

标签: symfony composer-php symfony5


【解决方案1】:

PHPUnit 4.7.7 已经过时了(2015 年 7 月发布),它的依赖与 Symfony 5.3 的要求相冲突。您应该从 PHAR 安装 PHPUnit(这是推荐的方式),或者将其升级到更新的版本

【讨论】:

    【解决方案2】:

    我解决了这个问题。问题是 composer.lock 与 composer.json 不一致,所以我执行了以下步骤:

    1. 删除 composer.lock 文件:

      rm -rf composer.lock

    2. 更新composer(它会自动创建composer.lock文件):

      composer update

    3. 验证 composer.lock 是否具有相同的依赖版本,必要时更新

    4. 保存并将修改推送到 git 和 heroku:

         git commit -m "Update composer files"
         git push
         git push heroku`
      

    【讨论】:

    • ....你是使用了和以前一样的依赖,还是升级了那些不兼容的版本? Symfony 5.3 应用程序将无法以任何方式使用 v4 中的 PHPUnit
    • 我升级了版本
    • 出于好奇:为什么要删除锁定文件来升级软件包?请注意,这会升级您正在使用的所有包,而不仅仅是那些需要更新的包
    猜你喜欢
    • 2016-11-19
    • 2021-12-19
    • 2013-12-04
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 2015-12-01
    • 2015-09-11
    • 2019-12-02
    相关资源
    最近更新 更多