symfony/flex

Invalid version string "^7.0"

janholusa opened this issue · 2 comments

Environment:

composer -V
Composer version 2.5.1 2022-12-22 15:33:54
$ composer show | grep flex
symfony/flex                            v2.2.4    Composer plugin for Symfony

Issue

Attempt to composer install afterwards vendor folder exists ends up with Invalid version string "^7.0"

$ composer install -vvvv
Running 2.5.1 (2022-12-22 15:33:54) with PHP 8.1.14 on Linux / 6.0.0-6-amd64
Reading ./composer.json (/home/user/Documents//project.backend/project-app/composer.json)
Loading config file /home/user/.config/composer/config.json
Loading config file /home/user/.config/composer/auth.json
Loading config file ./composer.json (/home/user/Documents//project.backend/project-app/composer.json)
Checked CA file /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
Failed to initialize global composer: Composer could not find the config file: /home/user/.config/composer/composer.json

Reading /home/user/Documents//project.backend/project-app/vendor/composer/installed.json
Loading plugin PackageVersions\Installer (from composer/package-versions-deprecated)
Loading plugin Symfony\Flex\Flex (from symfony/flex)
Reading ./composer.lock (/home/user/Documents//project.backend/project-app/composer.lock)
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Reading ./composer.lock (/home/user/Documents//project.backend/project-app/composer.lock)
> pre-pool-create: Symfony\Flex\Flex->truncatePackages
Reading /home/user/.cache/composer/repo/flex/symfony-recipes-flex-main-index.json from cache
Reading /home/user/.cache/composer/repo/flex/symfony-recipes-contrib-flex-main-index.json from cache
Downloading https://raw.githubusercontent.com/symfony/recipes/flex/main/index.json
Downloading https://raw.githubusercontent.com/symfony/recipes-contrib/flex/main/index.json
[304] https://raw.githubusercontent.com/symfony/recipes-contrib/flex/main/index.json
[304] https://raw.githubusercontent.com/symfony/recipes/flex/main/index.json
Built pool.
Generating rules
Resolving dependencies through SAT
Looking at all rules.

Dependency resolution completed in 0.000 seconds
> pre-operations-exec: Symfony\Flex\Flex->recordOperations

In VersionParser.php line 186:
                                 
  [UnexpectedValueException]     
  Invalid version string "^7.0"  
                                 

Exception trace:
  at phar:///usr/local/bin/composer/vendor/composer/semver/src/VersionParser.php:186
 Composer\Semver\VersionParser->normalize() at /home/user/Documents//project.backend/project-app/vendor/symfony/flex/src/Flex.php:279
 Symfony\Flex\Flex->recordOperations() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:206
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:166
 Composer\EventDispatcher\EventDispatcher->dispatchInstallerEvent() at phar:///usr/local/bin/composer/src/Composer/Installer.php:759
 Composer\Installer->doInstall() at phar:///usr/local/bin/composer/src/Composer/Installer.php:289
 Composer\Installer->run() at phar:///usr/local/bin/composer/src/Composer/Command/InstallCommand.php:146
 Composer\Command\InstallCommand->execute() at phar:///usr/local/bin/composer/vendor/symfony/console/Command/Command.php:298
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:1040
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:301
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:377
 Composer\Console\Application->doRun() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:171
 Symfony\Component\Console\Application->run() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:141
 Composer\Console\Application->run() at phar:///usr/local/bin/composer/bin/composer:88
 require() at /usr/local/bin/composer:29

Seems to be similar to #683

stof commented

The ->normalize() call on that line uses the version info from the symfony.lock file (for each recorded package) as argument.
There is no reason to have ^7.0 in this symfony.lock file as this is not a version but a version constraint.
Try looking at your symfony.lock file and its history to find out when this was introduced in it.

That was causing the exception. For some reason it contained

    "phpunit/php-code-coverage": {
        "version": "^7.0"
    },

Replacing version string with 9.2.23 solved it.
Thank you!