Skip to content
Latchkey

Composer "lock file does not contain a compatible set of packages"

composer install validates that the locked packages can actually be installed on the current PHP version and extensions. When the lock was resolved for a different platform than CI provides, the locked set is incompatible and Composer tells you to update.

What this error means

composer install fails with "Your lock file does not contain a compatible set of packages. Please run composer update." followed by a problem block naming a PHP version or extension the locked packages need.

composer
Your lock file does not contain a compatible set of packages. Please run
composer update.

  Problem 1
    - acme/widget 4.0.0 requires php ^8.2 but your php version (8.1.27)
      does not satisfy that requirement.

Diagnose it: platform requirements and auth

Composer resolves against the PHP version and extensions actually present, so a lockfile that installs locally can be unsatisfiable on a runner with a different PHP build.

Terminal
php -v && php -m | head -30
composer diagnose
composer check-platform-reqs

# install exactly what is locked, non-interactively
composer install --no-interaction --prefer-dist --no-progress

Common causes

The lock was resolved for a different PHP version

composer.lock was generated against a newer PHP than CI runs, so the locked package versions require a platform CI does not provide.

A required extension is absent in CI

The locked set assumes an extension (ext-intl, ext-gd) that the CI PHP build lacks, making the set uninstallable.

How to fix it

Run CI on the platform the lock targets

Match the CI PHP version and extensions to what the lock was resolved against.

.github/workflows/ci.yml
- uses: shivammathur/setup-php@v2
  with:
    php-version: '8.2'
    extensions: intl, gd
- run: composer install --no-interaction

Or re-resolve for the supported platform

If CI’s platform is the intended target, regenerate the lock against it and commit the result.

Terminal
composer update
git add composer.lock

How to prevent it

  • Pin a config.platform.php in composer.json so the lock resolves for your deploy target.
  • Run CI on the same PHP version and extensions you deploy on.
  • Commit composer.lock so CI installs the exact set you validated.

Frequently asked questions

What causes Composer "lock file does not contain a compatible set of packages"?
There are 2 common causes: the lock was resolved for a different php version and a required extension is absent in ci. composer.lock was generated against a newer PHP than CI runs, so the locked package versions require a platform CI does not provide.
How do I fix Composer "lock file does not contain a compatible set of packages"?
There are 2 fixes depending on which cause you have: run ci on the platform the lock targets and or re-resolve for the supported platform. Work through them in order, since the first is the most common.
What does Composer "lock file does not contain a compatible set of packages" actually mean?
composer install fails with "Your lock file does not contain a compatible set of packages.
How do I stop Composer "lock file does not contain a compatible set of packages" happening again?
Pin a config.platform.php in composer.json so the lock resolves for your deploy target. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card