From f776f524742a7cd53d7294016cba8a60a11e53cd Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 14 Oct 2021 15:12:29 +0200 Subject: [PATCH] Hint composer require alternatives if dep resolution fails, fixes #10136 --- src/Composer/Command/RequireCommand.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 578e2a208..8f511a015 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -387,6 +387,14 @@ EOT $status = $install->run(); if ($status !== 0) { + if ($status === Installer::ERROR_DEPENDENCY_RESOLUTION_FAILED) { + foreach ($this->normalizeRequirements($input->getArgument('packages')) as $req) { + if (!isset($req['version'])) { + $io->writeError('You can also try re-running composer require with an explicit version constraint, e.g. "composer require '.$req['name'].':*" to figure out if any version is installable, or "composer require '.$req['name'].':^2.1" if you know which you need.'); + break; + } + } + } $this->revertComposerFile(false); }