首页 > 解决方案 > Composer 更新成功,但 Composer 安装在创建的锁定文件上失败

问题描述

当我对我的 symfony 3.4.30 安装进行 composer update 时,它​​可以毫无问题地完成,但是当我尝试在创建的锁定文件上运行 composer install 时,它会抛出一个错误。

这发生在我的 CentOS 服务器和我的 MacOS 笔记本电脑上。我安装了最新的作曲家:

有谁知道发生了什么?

我已经尝试完全删除供应商目录和 composer.lock 文件,但没有成功。我还更新了我的作曲家版本,并清除了我的作曲家缓存:

composer clearcache
Cache directory does not exist (cache-vcs-dir):
Clearing cache (cache-repo-dir): /home/<user>/.composer/cache/repo
Clearing cache (cache-files-dir): /home/<user>/.composer/cache/files
Clearing cache (cache-dir): /home/<user>/.composer/cache
All caches cleared.

composer --version
Composer version 1.9.0 2019-08-02 20:55:32
php -dmemory_limit=-1 /usr/bin/composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 63 installs, 0 updates, 0 removals
  - Installing doctrine/cache (v1.8.0): Downloading (100%)
  - Installing doctrine/inflector (v1.3.0): Downloading (100%)
  - Installing paragonie/random_compat (v2.0.18): Downloading (100%)
  - Installing symfony/polyfill-php70 (v1.12.0): Downloading (100%)
  - Installing symfony/polyfill-util (v1.12.0): Downloading (100%)
  - Installing symfony/polyfill-php56 (v1.12.0): Downloading (100%)
  - Installing symfony/polyfill-mbstring (v1.12.0): Downloading (100%)
  - Installing symfony/symfony (v3.4.30): Downloading (100%)
  - Installing symfony/polyfill-intl-icu (v1.12.0): Downloading (100%)
  - Installing symfony/polyfill-ctype (v1.12.0): Downloading (100%)
  - Installing symfony/polyfill-apcu (v1.12.0): Downloading (100%)
  - Installing psr/simple-cache (1.0.1): Downloading (100%)
  - Installing psr/log (1.1.0): Downloading (100%)
  - Installing psr/link (1.0.0): Downloading (100%)
  - Installing psr/container (1.0.0): Downloading (100%)
  - Installing psr/cache (1.0.1): Downloading (100%)
  - Installing twig/twig (v2.11.3): Downloading (100%)
  - Installing fig/link-util (1.0.0): Downloading (100%)
  - Installing doctrine/lexer (1.0.2): Downloading (100%)
  - Installing doctrine/annotations (v1.7.0): Downloading (100%)
  - Installing doctrine/reflection (v1.0.0): Downloading (100%)
  - Installing doctrine/event-manager (v1.0.0): Downloading (100%)
  - Installing doctrine/collections (v1.6.2): Downloading (100%)
  - Installing doctrine/persistence (1.1.1): Downloading (100%)
  - Installing doctrine/common (v2.10.0): Downloading (100%)
  - Installing doctrine/doctrine-cache-bundle (1.3.5): Downloading (100%)
  - Installing symfony/polyfill-php73 (v1.12.0): Downloading (100%)
  - Installing symfony/polyfill-php72 (v1.12.0): Downloading (100%)
  - Installing symfony/polyfill-intl-idn (v1.12.0): Downloading (100%)
  - Installing symfony/mime (v4.3.3): Downloading (100%)
  - Installing jdorn/sql-formatter (v1.2.17): Downloading (100%)
  - Installing doctrine/dbal (v2.9.2): Downloading (100%)
  - Installing doctrine/doctrine-bundle (1.11.2): Downloading (100%)
  - Installing symfony/templating (v4.3.3): Downloading (100%)
  - Installing friendsofsymfony/user-bundle (v2.1.2): Downloading (100%)
  - Installing incenteev/composer-parameter-handler (v2.1.3): Downloading (100%)
  - Installing symfony/http-client-contracts (v1.1.5): Downloading (100%)
  - Installing symfony/http-client (v4.3.3): Downloading (100%)
  - Installing sensiolabs/security-checker (v6.0.2): Downloading (100%)
  - Installing sensio/distribution-bundle (v5.0.25): Downloading (100%)
  - Installing sensio/framework-extra-bundle (v5.4.1): Downloading (100%)
  - Installing monolog/monolog (1.24.0): Downloading (100%)
  - Installing symfony/monolog-bundle (v3.4.0): Downloading (100%)
  - Installing swiftmailer/swiftmailer (v5.4.12): Downloading (100%)
  - Installing symfony/swiftmailer-bundle (v2.6.7): Downloading (100%)
  - Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
  - Installing ralouphie/getallheaders (3.0.3): Downloading (100%)
  - Installing psr/http-message (1.0.1): Downloading (100%)
  - Installing guzzlehttp/psr7 (1.6.1): Downloading (100%)
  - Installing guzzlehttp/guzzle (6.3.3): Downloading (100%)
  - Installing sendgrid/php-http-client (3.9.6): Downloading (100%)
  - Installing sendgrid/sendgrid (7.3.0): Downloading (100%)
  - Installing google/recaptcha (1.2.2): Downloading (100%)
  - Installing excelwebzone/recaptcha-bundle (v1.5.15): Downloading (100%)
  - Installing sensio/generator-bundle (v3.1.7): Downloading (100%)
  - Installing symfony/phpunit-bridge (v3.4.30): Downloading (100%)
  - Installing fzaninotto/faker (v1.8.0): Downloading (100%)
  - Installing hamcrest/hamcrest-php (v2.0.0): Downloading (100%)
  - Installing mockery/mockery (1.2.3): Downloading (100%)
  - Installing doctrine/instantiator (1.2.0): Downloading (100%)
  - Installing doctrine/orm (v2.6.3): Downloading (100%)
  - Installing steevanb/doctrine-stats (1.3.3): Downloading (100%)
  - Installing steevanb/php-backtrace (2.0.1): Downloading (100%
Writing lock file
Generating autoload files
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: remove friendsofsymfony/user-bundle v2.1.2
    - Installation request for friendsofsymfony/user-bundle v2.1.2 -> satisfiable by friendsofsymfony/user-bundle[v2.1.2].
    - Conclusion: remove symfony/symfony v3.4.30
    - friendsofsymfony/user-bundle v2.1.2 requires symfony/templating ^2.8 || ^3.0 || ^4.0 -> satisfiable by symfony/templating[v4.3.3].
    - don't install symfony/symfony v3.4.30|remove symfony/templating v4.3.3
    - don't install symfony/templating v4.3.3|don't install symfony/symfony v3.4.30
    - Installation request for symfony/symfony v3.4.30 -> satisfiable by symfony/symfony[v3.4.30].

这是我的composer.json:

{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-4": {
            "AppBundle\\": "src/AppBundle"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        },
        "files": [
            "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
        ]
    },
    "require": {
        "php": ">=7.1.18",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/orm": "^2.5",
        "friendsofsymfony/user-bundle": "^2.0",
        "incenteev/composer-parameter-handler": "^2.0",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^5.0.0",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.6.4",
        "symfony/symfony": "^3.0",
        "twig/twig": "^1.0||^2.0",
        "guzzlehttp/guzzle": "^6.3",
        "symfony/templating": "^4.1",
        "sendgrid/sendgrid": "~7",
        "excelwebzone/recaptcha-bundle": "~1.5",
        "paragonie/random_compat": "^2.0"
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0",
        "fzaninotto/faker": "~1.2",
        "mockery/mockery": "~1.1",
        "steevanb/doctrine-stats": "^1.3",
        "steevanb/php-backtrace": "^2.0"
    },
    "scripts": {
        "symfony-scripts": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-install-cmd": [
            "@symfony-scripts"
        ],
        "post-update-cmd": [
            "@symfony-scripts"
        ]
    },
    "config": {
        "platform": {
            "php": "7.1.18"
        },
        "sort-packages": true
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-bin-dir": "bin",
        "symfony-var-dir": "var",
        "symfony-web-dir": "web",
        "symfony-tests-dir": "tests",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "3.4-dev"
        }
    }
}

标签: symfonycomposer-php

解决方案


TL;博士;

你解决它的方法是放弃

"symfony/templating": "^4.1",

从您的composer.json, 并重试整个过程。

请注意,symfony/templating它会将您的版本降级为3.4.x并可能导致您的副作用。


为什么?好吧,你的问题实际上来自这里:symfony/symfony 的 composer.json 的那一行:https ://github.com/symfony/symfony/blob/3.4/composer.json#L77

并由https://getcomposer.org/doc/04-schema.md#replace解释

因此,事实上,当您安装时symfony/symfony,它充当symfony/templating相同版本的替代品(所以3.4.30,在您的情况下)但是,您也有在您composer.json的版本中安装它的说明^4.3

这也是那些行告诉你的:

- don't install symfony/symfony v3.4.30|remove symfony/templating v4.3.3
- don't install symfony/templating v4.3.3|don't install symfony/symfony v3.4.30

它实际上指示您要么安装symfony/symfony v3.4.30ORsymfony/templating v4.3.3但不能同时安装两者,因为包的replace说明symfony/symfony使它与 完全相同的包symfony/templating,但在你的情况下不是相同的版本。

实际上,作曲家文档也准确地告诉了您:

这对于包含子包的包也很有用,例如主 symfony/symfony 包包含所有 Symfony 组件,这些组件也可以作为单独的包使用。如果您需要主包,它将自动满足单个组件之一的任何要求,因为它会替换它们。

来源: https ://getcomposer.org/doc/04-schema.md#replace


推荐阅读