Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Composer finds the package, yet no version of it fits your requirement

Your error

- Root composer.json requires vendor/package ^3.0, found vendor/package[1.0.0, 2.0.0, 2.1.0] but it does not match the constraint.2 more lines it can show

Fix it fast

Most common cause, 1 of 3

The constraint asks for a version that was never released

Require a range that includes a release the list shows.

Fix
composer require "vendor/package:^2.1"
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Composer says found vendor/package[versions] but it does not match the constraint when the package exists but no version, not even a pre-release, fits the requirement. Usually that version was never tagged, dev-master is now dev-main, or a dependency requires your own root package. Compare the bracketed list with your constraint. Composer 2.x wording; Composer 1 said rejected by your constraint.

  • Applies to Composer 2.0 to 2.11 (2.11.2 current)
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Put the versions Composer can see next to the constraint you wrote. The bracketed list in the error shows the same thing, and the tail of the message (a dev-master hint or a dep-on-root link) points straight at cause 2 or 3.

Run this first
composer show --all vendor/package
grep -n "vendor/package" composer.json

Then find the line you see in this list and open its fix:

  1. 1The constraint asks for a version that was never releasedThe highest version in the brackets is below the constraint, for example ^3.0 against a list ending at 2.1.0
  2. 2dev-master is required, but the default branch is now mainThe brackets list dev-main (or dev-default) and the message ends with Perhaps dev-master was renamed to dev-main?
  3. 3A dependency requires the root package you are working onThe package in the message is your own project, the list shows only a branch such as dev-main, and the line ends with See https://getcomposer.org/dep-on-root for details and assistance.

What does the error look like?

  • - Root composer.json requires vendor/package ^3.0, found vendor/package[1.0.0, 2.0.0, 2.1.0] but it does not match the constraint.
  • - Root composer.json requires vendor/package dev-master, found vendor/package[dev-main] but it does not match the constraint. Perhaps dev-master was renamed to dev-main?
  • The requested package vendor/package ^3.0 exists as vendor/package[1.0.0, 2.0.0] but these are rejected by your constraint.

Cause 1 of 3

The constraint asks for a version that was never released

You seeThe highest version in the brackets is below the constraint, for example ^3.0 against a list ending at 2.1.0

Check

In Composer 2 this sentence comes from the last fallback check: the package was found once both minimum-stability and the version requirement were ignored, so the requirement alone excludes every release. Had a beta or RC matched, the message would end with does not match your minimum-stability instead. A typo in the version, a major copied from documentation for an unreleased branch, or a fork that never pushed its tags all end here. Composer 1 described the same case as exists as ... but these are rejected by your constraint.

Check
composer show --all vendor/package | grep -i versions

Fix

Require a range that includes a release the list shows. If you need a feature from the next major, wait for its tag or ask the maintainer to publish one.

Fix
composer require "vendor/package:^2.1"

Verify

composer.json holds the new constraint and the package is installed.

Verify
composer show vendor/package | grep -E "^(name|versions)"

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

dev-master is required, but the default branch is now main

You seeThe brackets list dev-main (or dev-default) and the message ends with Perhaps dev-master was renamed to dev-main?

Check

Composer names a branch version dev- plus the branch name. When a repository renames master to main, the version dev-master disappears and dev-main takes its place. Composer adds the rename hint only when the constraint is exactly dev-master and a dev-main or dev-default version is in the list.

Check
composer show --all vendor/package | grep -E "dev-(main|master|default)"

Fix

Require the branch under its current name, or better, a tagged release if the project has one.

Fix
composer require "vendor/package:dev-main"

Verify

The update resolves and composer.json now shows dev-main.

Verify
grep -n "vendor/package" composer.json

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

A dependency requires the root package you are working on

You seeThe package in the message is your own project, the list shows only a branch such as dev-main, and the line ends with See https://getcomposer.org/dep-on-root for details and assistance.

Check

When a plugin or test dependency requires the package whose repository you are in, Composer can only offer the root package's own version. On a branch with no branch alias that version is dev-main, which does not satisfy a range like ^2.0. CI systems that use shallow clones can also stop Composer from detecting the root version at all.

Check
grep -n -A3 "branch-alias" composer.json

Fix

Commit a branch alias on the branch, so dev-main counts as the next version line. In CI, also tell Composer which version the checkout is with COMPOSER_ROOT_VERSION, as the Composer troubleshooting guide shows.

Fix
{
    "extra": {
        "branch-alias": {
            "dev-main": "2.0.x-dev"
        }
    }
}

# CI job
COMPOSER_ROOT_VERSION=dev-main composer install

Verify

The install finishes without the dep-on-root problem.

Verify
COMPOSER_ROOT_VERSION=dev-main composer install

Confirmed by getcomposer.org

Did this fix it?

How do I stop it coming back?

  • Before raising a constraint, run composer show --all for that package and pick a version that the list really contains.
  • Point branch requirements at the branch name the repository uses today, and switch to a tagged release as soon as one exists.
  • In libraries, keep a branch-alias on the main branch so dependent packages resolve during development.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.