skip to Main Content

I’m writing a PHP application based on Symfony v5.0.11. Now I want to upgrade Symfony to the ^v5.2. (The Composer version is 2.0.12.)

$ composer require symfony/framework-bundle:^5.2
./composer.json has been updated
Running composer update symfony/framework-bundle
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - symfony/framework-bundle[v5.2.0, ..., v5.2.6] require symfony/cache ^5.2 -> found symfony/cache[v5.2.0, ..., v5.2.6] but the package is fixed to v5.0.11 (lock file version) by a partia
l update and that version does not match. Make sure you list it as an argument for the update command.
    - Root composer.json requires symfony/framework-bundle ^5.2 -> satisfiable by symfony/framework-bundle[v5.2.0, ..., v5.2.6].

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

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

It hasn’t worked, because the symfony/cache package is locked to the v5.0.11 version in composer.lock. But when I try using the --with-all-dependencies option, as suggested in the error message:

$ composer require --update-with-all-dependencies symfony/framework-bundle:^5.2
./composer.json has been updated
Running composer update symfony/framework-bundle --with-all-dependencies
Loading composer repositories with package information
Restricting packages listed in "symfony/symfony" to "5.0.*"
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - symfony/framework-bundle[v5.2.0, ..., v5.2.6] require symfony/cache ^5.2 -> found symfony/cache[v5.2.0, ..., v5.2.6] but these were not loaded, likely because it conflicts with another
 require.
    - Root composer.json requires symfony/framework-bundle ^5.2 -> satisfiable by symfony/framework-bundle[v5.2.0, ..., v5.2.6].


Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Now the problem is, that Composer cannot install the needed version of the package symfony/cache, possibly "because it conflicts with another require".

How to solve these / such Composer issues cleanly? ("Clean" means here: without resetting the project, running the across-the-board composer update, or making other brutal stuff with unpredictable side-effects.)


UPDATE

  • composer.json
  • composer.lock
  • symfony.lock

composer.json

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": "^7.3.0 || ^8.0.0",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "knplabs/knp-markdown-bundle": "^1.9",
        "paragonie/sodium_compat": "^1.15",
        "sensio/framework-extra-bundle": "^6.0",
        "sentry/sentry-symfony": "^4.0",
        "symfony/asset": "5.0.*",
        "symfony/console": "5.0.*",
        "symfony/debug-bundle": "5.0.*",
        "symfony/dotenv": "5.0.*",
        "symfony/flex": "^1.3.1",
        "symfony/framework-bundle": "5.0.*",
        "symfony/monolog-bundle": "^3.0",
        "symfony/profiler-pack": "*",
        "symfony/routing": "5.1.*",
        "symfony/twig-pack": "^1.0",
        "symfony/var-dumper": "5.0.*",
        "symfony/webpack-encore-bundle": "^1.7",
        "symfony/yaml": "5.0.*"
    },
    "require-dev": {
        "symfony/maker-bundle": "^1.30",
        "symfony/profiler-pack": "^1.0"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true,
        "platform": {}
    },
    "autoload": {
        "psr-4": {
            "App\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\Tests\": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": true,
            "require": "5.0.*"
        }
    }
}

composer.lock

{
    ...
        {
            "name": "symfony/framework-bundle",
            "version": "v5.0.11",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/framework-bundle.git",
                "reference": "0fc0a93f8bbe465d0b483e21b087d432baa92c16"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/framework-bundle/zipball/0fc0a93f8bbe465d0b483e21b087d432baa92c16",
                "reference": "0fc0a93f8bbe465d0b483e21b087d432baa92c16",
                "shasum": ""
            },
            "require": {
                "ext-xml": "*",
                "php": ">=7.2.5",
                "symfony/cache": "^4.4|^5.0",
                "symfony/config": "^5.0",
                "symfony/dependency-injection": "^5.0.1",
                "symfony/error-handler": "^4.4.1|^5.0.1",
                "symfony/filesystem": "^4.4|^5.0",
                "symfony/finder": "^4.4|^5.0",
                "symfony/http-foundation": "^4.4|^5.0",
                "symfony/http-kernel": "^5.0",
                "symfony/polyfill-mbstring": "~1.0",
                "symfony/routing": "^5.0"
            },
            "conflict": {
                "doctrine/persistence": "<1.3",
                "phpdocumentor/reflection-docblock": "<3.0",
                "phpdocumentor/type-resolver": "<0.2.1",
                "phpunit/phpunit": "<5.4.3",
                "symfony/asset": "<4.4",
                "symfony/browser-kit": "<4.4",
                "symfony/console": "<4.4",
                "symfony/dom-crawler": "<4.4",
                "symfony/dotenv": "<4.4",
                "symfony/form": "<4.4",
                "symfony/http-client": "<4.4",
                "symfony/lock": "<4.4",
                "symfony/mailer": "<4.4",
                "symfony/messenger": "<4.4",
                "symfony/mime": "<4.4",
                "symfony/property-info": "<4.4",
                "symfony/serializer": "<4.4",
                "symfony/stopwatch": "<4.4",
                "symfony/translation": "<5.0",
                "symfony/twig-bridge": "<4.4",
                "symfony/twig-bundle": "<4.4",
                "symfony/validator": "<4.4",
                "symfony/web-profiler-bundle": "<4.4",
                "symfony/workflow": "<4.4"
            },
            "require-dev": {
                "doctrine/annotations": "~1.7",
                "doctrine/cache": "~1.0",
                "paragonie/sodium_compat": "^1.8",
                "phpdocumentor/reflection-docblock": "^3.0|^4.0",
                "symfony/asset": "^4.4|^5.0",
                "symfony/browser-kit": "^4.4|^5.0",
                "symfony/console": "^4.4|^5.0",
                "symfony/css-selector": "^4.4|^5.0",
                "symfony/dom-crawler": "^4.4|^5.0",
                "symfony/dotenv": "^4.4|^5.0",
                "symfony/expression-language": "^4.4|^5.0",
                "symfony/form": "^4.4|^5.0",
                "symfony/http-client": "^4.4|^5.0",
                "symfony/lock": "^4.4|^5.0",
                "symfony/mailer": "^4.4|^5.0",
                "symfony/messenger": "^4.4|^5.0",
                "symfony/mime": "^4.4|^5.0",
                "symfony/polyfill-intl-icu": "~1.0",
                "symfony/process": "^4.4|^5.0",
                "symfony/property-info": "^4.4|^5.0",
                "symfony/security-csrf": "^4.4|^5.0",
                "symfony/security-http": "^4.4|^5.0",
                "symfony/serializer": "^4.4|^5.0",
                "symfony/stopwatch": "^4.4|^5.0",
                "symfony/string": "~5.0.0",
                "symfony/translation": "^5.0",
                "symfony/twig-bundle": "^4.4|^5.0",
                "symfony/validator": "^4.4|^5.0",
                "symfony/web-link": "^4.4|^5.0",
                "symfony/workflow": "^4.4|^5.0",
                "symfony/yaml": "^4.4|^5.0",
                "twig/twig": "^2.10|^3.0"
            },
            "suggest": {
                "ext-apcu": "For best performance of the system caches",
                "symfony/console": "For using the console commands",
                "symfony/form": "For using forms",
                "symfony/property-info": "For using the property_info service",
                "symfony/serializer": "For using the serializer service",
                "symfony/validator": "For using validation",
                "symfony/web-link": "For using web links, features such as preloading, prefetching or prerendering",
                "symfony/yaml": "For using the debug:config and lint:yaml commands"
            },
            "type": "symfony-bundle",
            "extra": {
                "branch-alias": {
                    "dev-master": "5.0-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Symfony\Bundle\FrameworkBundle\": ""
                },
                "exclude-from-classmap": [
                    "/Tests/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "[email protected]"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony FrameworkBundle",
            "homepage": "https://symfony.com",
            "support": {
                "source": "https://github.com/symfony/framework-bundle/tree/v5.0.11"
            },
            "funding": [
                {
                    "url": "https://symfony.com/sponsor",
                    "type": "custom"
                },
                {
                    "url": "https://github.com/fabpot",
                    "type": "github"
                },
                {
                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
                    "type": "tidelift"
                }
            ],
            "time": "2020-07-23T08:36:09+00:00"
        },
    ...
}

symfony.lock

{
    ...
    "symfony/framework-bundle": {
        "version": "4.4",
        "recipe": {
            "repo": "github.com/symfony/recipes",
            "branch": "master",
            "version": "4.4",
            "ref": "23ecaccc551fe2f74baf613811ae529eb07762fa"
        },
        "files": [
            "config/bootstrap.php",
            "config/packages/cache.yaml",
            "config/packages/framework.yaml",
            "config/packages/test/framework.yaml",
            "config/routes/dev/framework.yaml",
            "config/services.yaml",
            "public/index.php",
            "src/Controller/.gitignore",
            "src/Kernel.php"
        ]
    },
    ...
}

2

Answers


  1. Considering your output:

    Restricting packages listed in "symfony/symfony" to "5.0.*"

    You currently have something like this in your composer.json:

    "extra": {
        "symfony": {
          "require": "5.0.*"
        }
      },
    

    Which means you can’t update to Symfony packaged greater than 5.0.*.

    But now you are trying to install the framework-bundle on a greater version, but you can’t update the individual components.

    The way to do this "cleanly" is to do it step by step.

    First change your required Symfony version to 5.2.*, update all Symfony packages to this version (which yes, will require you issuing a composer update), deal with any problems (if any) after the update, and then install the framework-bundle you were going to install.

    Login or Signup to reply.
  2. You are already using multiple versions of Symfony packages in your composer.json, like:

        "symfony/asset": "5.0.*",
        "symfony/console": "5.0.*",
        "symfony/debug-bundle": "5.0.*",
        "symfony/dotenv": "5.0.*",
        "symfony/framework-bundle": "5.0.*",
        "symfony/routing": "5.1.*",
        "symfony/yaml": "5.0.*"
    

    You should clean that up to avoid incompatible packages. Do this either by using Flex, or by setting all package versions by hand


    Usage of Flex

    Set all Symfony related dependencies to "*", configure the Symfony version like this:

    "extra": {
      "symfony": {
        "require": "5.2.*"
      }
    },
    

    Afterwards, update the Symfony dependencies through composer update "symfony/*".

    Any later upgrade to the next version requires only a single change in this section.


    "Manual" configuration

    Set all Symfony related dependencies to "5.2.*", update them through composer update "symfony/*"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search