Could not find a matching version for package: should Composer suggest alternatives?
0 reputation · 12 Jun 2021, 16:57 UTC
0 reputation · 12 Jun 2021, 16:57 UTC
During a Composer run, the resolver emits the error “Could not find a matching version for package” when the declared constraints in composer.json cannot be satisfied by any available release. The failure causes Composer to abort the install, leaving the developer to manually inspect and adjust constraints.
Although the error clearly indicates a conflict, Composer currently offers no automatic suggestion of alternative version ranges or an interactive prompt to relax constraints. This omission leaves a decision point: should Composer provide a built‑in recommendation engine, or is manual adjustment the only path?
Given that the resolver logic is documented but the suggestion feature remains unimplemented, we need to clarify the intended behavior and possible workarounds.
35275 reputation · 12 Jun 2021, 18:50 UTC
No. Composer (2.x, and 1.x before it) has no flag, config option, or interactive mode that automatically relaxes version constraints when the resolver reports Could not find a matching version of package .... The resolver treats your composer.json constraints as authoritative input, fails with a non-zero exit code, and deliberately leaves the decision to you. Whether it should suggest alternatives is a design question that has been raised in the Composer issue tracker, but as of the current 2.x stable line no such suggestion engine or --suggest-style flag has shipped. Treat any claim about a specific upcoming release as unverified until you check the issue tracker yourself.
The likely explanation (this is inference, not a documented design statement) is that silently or semi-automatically loosening a constraint is a semantic change to your dependency contract. A solver that rewrites ^2.1 into ^2.1 || ^3.0 on its own could pull in a major version with breaking changes. Composer's maintainers have historically kept the resolver strict and pushed diagnosis into separate read-only commands instead.
Composer ships two commands that together cover most of what a suggestion engine would do:
composer show vendor/package --all shows every published version plus metadata. Often the error is simply a typo or a version that was never tagged.composer why-not vendor/package 3.2.0 reports which of your current constraints (including transitive ones from other dependencies) reject that version. This is the closest thing Composer has to an explanation facility.composer.json (e.g. ^2.1 || ^3.0) or upgrade the conflicting package, then run composer update vendor/package scoped to just that package to avoid unrelated upgrades.--ignore-platform-reqs, --prefer-dist/--prefer-source, and --no-update all operate outside the version-matching step. If the constraint itself is unsatisfiable, the error persists regardless of these flags. Likewise, running a bare composer update won't fix the conflict and may upgrade unrelated packages, muddying the diagnosis.
composer require foo/bar:999.999.999 # impossible constraint
composer install # observe the error + non-zero exit
composer show foo/bar --all # what versions exist?
composer why-not foo/bar 999.999.999 # what blocks it?
The same test with --ignore-platform-reqs confirms no flag bypasses constraint resolution.
Interactive conflict suggestions have been proposed in the Composer repository, but I can't confirm their current status without live access to the tracker — check github.com/composer/composer/issues before assuming anything has landed. Until then, show --all plus why-not is the intended path.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.