错误信息如下:
hrs@hrs-desktop:~/drupal$ ddev composer require drush/drush
./composer.json has been updated
Running composer update drush/drush
> Drupal\Composer\Composer::ensureComposerVersion
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 drupal/core 12.x-dev -> satisfiable by drupal/core[12.x-dev (alias of dev-main)].
- Root composer.json requires drush/drush * -> satisfiable by drush/drush[dev-cim-module-install-req, ..., dev-php8, 6.0.0-rc1, ..., 6.x-dev, 7.0.0-alpha1, ..., 7.x-dev, 8.0.0-beta11, ..., 8.x-dev, 9.0.0-alpha1, ..., 9.x-dev, 10.0.0-alpha1, ..., 10.x-dev, 11.0.0-rc1, ..., 11.x-dev, 12.0.0-beta1, ..., 12.x-dev, 13.0.0-beta1, ..., 13.x-dev, 14.x-dev].
- consolidation/annotated-command[4.10.0, ..., 4.x-dev] require symfony/console ^4.4.8 || ^5 || ^6 || ^7 -> found symfony/console[v4.4.8, ..., 4.4.x-dev, v5.0.0-BETA1, ..., 5.4.x-dev, v6.0.0-BETA1, ..., 6.4.x-dev, v7.0.0-BETA1, ..., 7.4.x-dev] but the package is fixed to v8.0.6 (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.
- drupal/core 12.x-dev conflicts with drush/drush <12.4.3.
- drush/drush[dev-inf-admin, dev-master, dev-greg-1-anderson-robo-2-partII, dev-robo-2, 9.0.0-beta8, ..., 9.x-dev, 10.0.0-alpha1, ..., 10.3.5] require composer/semver ^1.4 -> found composer/semver[1.4.0, ..., 1.x-dev] but the package is fixed to 3.4.4 (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.
- drush/drush[dev-reenable-cache-commands-testing, ..., dev-php8, 7.2.0, ..., 7.x-dev, 8.0.2, ..., 8.x-dev, 9.0.0-alpha1, ..., 9.0.0-beta7, 10.3.6, ..., 10.x-dev, 11.0.0-rc1, ..., 11.0.5] require psr/log ~1.0 -> found psr/log[1.0.0, ..., 1.1.4] but the package is fixed to 3.0.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.
- drush/drush[dev-deprecate-global-config-cmds, dev-ignore-commands-in-parent, dev-no-irc, dev-single-autoloader-only, dev-d10-low-tests, dev-test-74, 11.0.6, ..., 11.x-dev] require symfony/event-dispatcher ^4.0 || ^5.0 || ^6.0 -> found symfony/event-dispatcher[v4.0.0-BETA1, ..., 4.4.x-dev, v5.0.0-BETA1, ..., 5.4.x-dev, v6.0.0-BETA1, ..., 6.4.x-dev] but the package is fixed to v8.0.4 (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.
- drush/drush[dev-cim-module-install-req, dev-cmds-to-static-create, dev-deprecate-io-trait, dev-si-with-recipes-12x, dev-config-check-12.x, dev-weitzman-patch-1, 12.0.0-beta1, ..., 12.x-dev] require symfony/event-dispatcher ^6 -> found symfony/event-dispatcher[v6.0.0-BETA1, ..., 6.4.x-dev] but the package is fixed to v8.0.4 (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.
- drush/drush[dev-revert-drush-bash-script, dev-requirements-compat, dev-test-on-8.4, dev-chunk/changes-1772775428089-1772775428089, dev-zActions, dev-viz, dev-highest, dev-revert-6192-actions, dev-autowire-params, 13.0.0-beta1, ..., 13.x-dev, 14.x-dev] require symfony/event-dispatcher ^6 || ^7 -> found symfony/event-dispatcher[v6.0.0-BETA1, ..., 6.4.x-dev, v7.0.0-BETA1, ..., 7.4.x-dev] but the package is fixed to v8.0.4 (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.
- drush/drush[7.0.0-alpha5, ..., 7.1.0, 8.0.0-beta11, ..., 8.0.0-rc2] require symfony/yaml ~2.2 -> found symfony/yaml[v2.2.0, ..., 2.8.x-dev] but the package is fixed to v8.0.6 (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.
- drush/drush[7.0.0-alpha1, ..., 7.0.0-alpha4] require symfony/yaml 2.2.1 -> found symfony/yaml[v2.2.1] but the package is fixed to v8.0.6 (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.
- drush/drush[8.0.0-rc3, ..., 8.0.1] require symfony/yaml 2.7.* -> found symfony/yaml[v2.7.0-BETA1, ..., 2.7.x-dev] but the package is fixed to v8.0.6 (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.
- drush/drush dev-formatting-juggle requires consolidation/output-formatters dev-use-command-directly-of as 4.x-dev -> found consolidation/output-formatters[dev-fields-came-from-default, ..., dev-property-parser, 0.1.0, ..., 0.2.3, 1.0.0-beta1, ..., 1.x-dev, 2.0.0-beta1, ..., 2.1.3, 3.0.0, ..., 3.x-dev, 4.0.0, ..., 4.x-dev] but it does not match the constraint.
- drush/drush dev-requirements-compat-symfony8 requires consolidation/annotated-command ^4.10.2 -> satisfiable by consolidation/annotated-command[4.10.2, 4.10.3, 4.10.4, 4.x-dev].
- drush/drush dev-table-empty-message requires consolidation/output-formatters dev-table-empty-message as 4.3.1 -> found consolidation/output-formatters[dev-fields-came-from-default, ..., dev-property-parser, 0.1.0, ..., 0.2.3, 1.0.0-beta1, ..., 1.x-dev, 2.0.0-beta1, ..., 2.1.3, 3.0.0, ..., 3.x-dev, 4.0.0, ..., 4.x-dev] but it does not match the constraint.
- Conclusion: don't install drupal/core 12.x-dev (conflict analysis result)
Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require drush/drush:*" to figure out if any version is installable, or "composer require drush/drush:^2.1" if you know which you need.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
Composer [require drush/drush] failed, composer command failed: exit status 2. stderr=这个错误是因为 Composer 依赖版本冲突。
你的项目使用的是 Drupal 12.x-dev(需要 Symfony 8 组件),但 Drush 的许多版本要求较旧的 Symfony 组件。
🔧 解决方案
方法一:使用 --with-all-dependencies 强制更新(推荐)
ddev composer require drush/drush --with-all-dependencies 这会允许 Composer 同时升级或降级其他依赖包以解决冲突。
方法二:安装支持 Drupal 12 的 Drush 版本 Drush 13 和 14 版本支持更新的 Symfony 组件。
尝试指定版本:
ddev composer require drush/drush:^13 --with-all-dependencies 或
ddev composer require drush/drush:^14 --with-all-dependencies 方法三:先查看兼容版本 如果不确定哪个版本合适,可以先查看可用的 Drush 版本:
bash ddev composer show drush/drush --all | grep -E "^versions|^12\."
📋 关于版本兼容 根据错误信息中的关键点:
你的 Drupal core 是 12.x-dev Drupal 12 与 drush/drush < 12.4.3 冲突 你当前的 Symfony 组件是 v8.x,需要 Drush 支持 Symfony 6/7/8 的版本 Drush 版本与 Drupal 12 的兼容性: Drush 12.4.3+:部分支持 Drush 13+:完整支持 Drupal 12 Drush 14:最新,支持 Symfony 8
✅ 建议执行
ddev composer require drush/drush:^14 --with-all-dependencies 这应该能成功安装与你的 Drupal 12 环境兼容的 Drush 版本。
评论