Symfony 6.1安装hwi/oauth-bundle遇依赖无法解析错误
问题场景
在PHP 8.1环境的Symfony 6.1项目中执行命令:
composer require hwi/oauth-bundle
收到以下依赖冲突错误:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- hwi/oauth-bundle[1.4.0, ..., 1.4.5] require symfony/framework-bundle 4.4|5.1 -> found symfony/framework-bundle[v4.4.0, ..., v4.4.46, v5.1.0, ..., v5.4.13] but it conflicts with your root composer.json require (6.1.5).
- Root composer.json requires hwi/oauth-bundle ^1.4 -> satisfiable by hwi/oauth-bundle[1.4.0, ..., 1.4.5].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 hwi/oauth-bundle:*" to figure out if any version is installable, or "composer require hwi/oauth-bundle:^2.1" if you know which you need.Installation failed, reverting ./composer.json and ./composer.lock to their original content.
解决方案
冲突核心是HWI OAuth Bundle 1.4.x版本仅兼容Symfony 4.4/5.1,而你的项目使用Symfony 6.1,需安装支持Symfony 6的2.x版本:
- 直接安装兼容版本:
composer require hwi/oauth-bundle:^2.1
- 若安装时仍有其他依赖约束问题,添加
-W参数允许Composer调整相关依赖版本:
composer require hwi/oauth-bundle:^2.1 -W
- 安装完成后,可执行以下命令验证版本与依赖:
composer show hwi/oauth-bundle
内容的提问来源于stack exchange,提问作者Thomas Bortolato

