微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试使用 composer

如何解决尝试使用 composer

我正在尝试开发一个项目,但在安装带有 Composer 的 Sylius 时遇到问题。

这是我的composer.json

{
    "type": "project","license": "proprietary","minimum-stability": "dev","prefer-stable": true,"require": {
        "PHP": ">=7.0","ext-ctype": "*","ext-iconv": "*","composer/package-versions-deprecated": "1.11.99.2","doctrine/annotations": "^1.0","doctrine/doctrine-bundle": "^2.4","doctrine/doctrine-migrations-bundle": "^3.1","doctrine/orm": "^2.9","PHPdocumentor/reflection-docblock": "^5.2","sensio/framework-extra-bundle": "^6.1","symfony/apache-pack": "^1.0","symfony/asset": "5.3.*","symfony/console": "5.3.*","symfony/dotenv": "5.3.*","symfony/expression-language": "5.3.*","symfony/flex": "^1.3.1","symfony/form": "5.3.*","symfony/framework-bundle": "5.3.*","symfony/http-client": "5.3.*","symfony/intl": "5.3.*","symfony/mailer": "5.3.*","symfony/mime": "5.3.*","symfony/monolog-bundle": "^3.1","symfony/notifier": "5.3.*","symfony/process": "5.3.*","symfony/property-access": "5.3.*","symfony/property-info": "5.3.*","symfony/proxy-manager-bridge": "5.3.*","symfony/runtime": "5.3.*","symfony/security-bundle": "5.3.*","symfony/serializer": "5.3.*","symfony/string": "5.3.*","symfony/translation": "5.3.*","symfony/twig-bundle": "^5.3","symfony/validator": "5.3.*","symfony/web-link": "5.3.*","symfony/webpack-encore-bundle": "^1.11","symfony/yaml": "5.3.*","twig/extra-bundle": "^2.12|^3.0","twig/twig": "^2.12|^3.0"
    },"require-dev": {
        "PHPunit/PHPunit": "^9.5","symfony/browser-kit": "^5.3","symfony/css-selector": "^5.3","symfony/debug-bundle": "^5.3","symfony/maker-bundle": "^1.0","symfony/PHPunit-bridge": "^5.3","symfony/stopwatch": "^5.3","symfony/var-dumper": "^5.3","symfony/web-profiler-bundle": "^5.3"
    },"config": {
        "optimize-autoloader": true,"preferred-install": {
            "*": "dist"
        },"sort-packages": true
    },"autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },"autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },"replace": {
        "symfony/polyfill-ctype": "*","symfony/polyfill-iconv": "*","symfony/polyfill-PHP72": "*"
    },"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": false,"require": "5.3.*"
        }
    }
}

当我输入 composer require sylius/product-bundle 时出现此错误

Using version ^0.15.0 for sylius/product-bundle
./composer.json has been updated
Running composer update sylius/product-bundle
Loading composer repositories with package information
Updating dependencies
Your requirements Could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires sylius/product-bundle ^0.15.0 -> satisfiable by sylius/product-bundle[v0.15.0].
    - sylius/product-bundle v0.15.0 requires symfony/framework-bundle ~2.3 -> found symfony/framework-bundle[v2.3.0,...,2.8.x-dev] 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.

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

因此,据我了解,composer 尝试获取 0.15.0sylius/product-bundle 版本,这显然不适用于我的配置,因为它需要旧版本的依赖项,如下所示。

sylius/product-bundle v0.15.0

仅当我尝试使用 composer require sylius/product-bundle:1.9.4 要求更新版本时,我也会收到错误

  [invalidargumentexception]
  Package sylius/product-bundle at version 1.9.4 has a PHP requirement incompatible with your PHP version,PHP extensions and Composer version

考虑到其依赖项的所需版本,这个应该可以解决问题

sylius/product-bundle v1.9.4

我终于尝试了 composer require sylius/product-bundle:1.9.4 --ignore-platform-reqs,这再次给了我一个错误,但又是一个不同的错误

./composer.json has been updated
Running composer update sylius/product-bundle
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
    - gedmo/doctrine-extensions[v2.3.10,v2.4.x-dev,v3.0.0-beta,v3.0.1] require doctrine/common ~2.4 -> found doctrine/common[2.4.0-RC1,2.13.x-dev] but the package is fixed to 3.1.2 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - gedmo/doctrine-extensions[v2.3.4,v2.3.9] require doctrine/common >=2.2,<2.5-dev -> found doctrine/common[2.2.0BETA1,2.4.x-dev] but the package is fixed to 3.1.2 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - gedmo/doctrine-extensions[v3.0.0-beta2,v3.0.5] require doctrine/cache ^1.0 -> found doctrine/cache[v1.0,1.11.x-dev] but the package is fixed to 2.0.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - sylius/product-bundle v1.9.4 requires stof/doctrine-extensions-bundle ^1.4 -> satisfiable by stof/doctrine-extensions-bundle[v1.4.0,v1.5.0,v1.6.0,1.6.x-dev (alias of dev-master)].
    - stof/doctrine-extensions-bundle 1.6.x-dev is an alias of stof/doctrine-extensions-bundle dev-master and thus requires it to be installed too.
    - stof/doctrine-extensions-bundle v1.4.0 requires gedmo/doctrine-extensions ^2.3.4 -> satisfiable by gedmo/doctrine-extensions[v2.3.4,v2.4.x-dev].
    - stof/doctrine-extensions-bundle[dev-master,v1.6.0] require gedmo/doctrine-extensions ^2.3.4 || ^3.0.0 -> satisfiable by gedmo/doctrine-extensions[v2.3.4,v3.0.5].
    - Root composer.json requires sylius/product-bundle 1.9.4 -> satisfiable by sylius/product-bundle[v1.9.4].

Use the option --with-all-dependencies (-W) to allow upgrades,reverting ./composer.json and ./composer.lock to their original content.

我有 PHP cli v8.0.6、Composer v2.0.12 和 Symfony cli v4.25.2

解决方法

你有两个问题:

  • 您已安装 Symfony '5.3',该版本仅在一天前发布。
  • 您使用的是 PHP 8,Sylius 不支持该版本。通过使用 PHP 8,您最终会安装与 Sylius 不兼容的依赖项版本。

由于当前版本的 Sylius supports up to 5.2 和 PHP ^7.3,您必须降级到 Sf 5.2 和 PHP >= 7.3 && PHP = 8 已经完成。

我建议使用标准 Sylius 安装,但在使用 PHP 8 时尝试使用推荐的文档方式 (composer create-project sylius/sylius-standard acme) 安装 Sylius 也会失败。但降级为 PHP 7.4 并运行 create-project 命令确实有效。

项目似乎进入了依赖地狱的开发阶段。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。