Maaz Zindani

Loading the index…

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

PHP cannot find Composer\InstalledVersions at runtime

Your error

Class "Composer\InstalledVersions" not found1 more line it can show

Fix it fast

Most common cause, 1 of 3

Composer 1 installed the project's vendor folder

Move the binary to the 2.x channel, then build vendor/ again from the lock file.

Fix
composer self-update --2
rm -rf vendor
composer install
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Class "Composer\InstalledVersions" not found means the vendor folder or its autoloader was produced by Composer 1, which predates that class; it arrived with composer-runtime-api 2.0 in Composer 2. Run composer self-update --2 (current stable is 2.11.2), then reinstall vendor/ or run composer dump-autoload. For global tools, follow with composer global update.

  • Applies to Composer 2.11.2, Composer 2.2.32 LTS, PHP 8.x and 7.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Run these three lines in the project root. They show the Composer version, whether the class file exists, and whether Composer's own autoloader can load it. The pattern of answers points to one cause below.

Run this first
composer --version
ls -l vendor/composer/InstalledVersions.php
php -r 'require "vendor/autoload.php"; var_dump(class_exists("Composer\\InstalledVersions"));'

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

  1. 1Composer 1 installed the project's vendor foldercomposer --version prints 1.x, and vendor/composer/InstalledVersions.php does not exist
  2. 2The autoload files were dumped by an older Composer than the packagesInstalledVersions.php exists in vendor/composer, yet autoload_classmap.php has no line for it
  3. 3A globally installed tool still runs on a Composer 1 installThe project checks pass, but a command such as an installer you added with composer global require fails, and the stack trace points into the global Composer directory

What does the error look like?

  • Class "Composer\InstalledVersions" not found
  • Class 'Composer\InstalledVersions' not found

Cause 1 of 3

Composer 1 installed the project's vendor folder

You seecomposer --version prints 1.x, and vendor/composer/InstalledVersions.php does not exist

Check

The InstalledVersions class is part of composer-runtime-api 2.0, so a vendor folder built by Composer 1 never gets the file, and any package that calls it stops with Class Composer\InstalledVersions not found. getcomposer.org marks 1.10.28, the final 1.x release, as end of life.

Check
composer --version

Fix

Move the binary to the 2.x channel, then build vendor/ again from the lock file. If Composer came from an OS package manager, self-update is unavailable; install the current composer.phar from getcomposer.org instead.

Fix
composer self-update --2
rm -rf vendor
composer install

Verify

The class file is present and the one-line PHP check prints bool(true).

Verify
php -r 'require "vendor/autoload.php"; var_dump(class_exists("Composer\\InstalledVersions"));'

Confirmed by getcomposer.org

Did this fix it?

Cause 2 of 3

The autoload files were dumped by an older Composer than the packages

You seeInstalledVersions.php exists in vendor/composer, yet autoload_classmap.php has no line for it

Check

Composer 2 adds Composer\InstalledVersions to the generated classmap every time it writes the autoloader. If a deploy step or another machine later regenerated the autoload files with Composer 1, that entry is missing even though the PHP file sits right there.

Check
grep -c "InstalledVersions" vendor/composer/autoload_classmap.php

Fix

Regenerate the autoloader with Composer 2 on the machine that serves the app, and change the build image or deploy script that still carries the old binary.

Fix
composer --version
composer dump-autoload --optimize

Verify

grep now counts at least one match, and the page or command that failed loads.

Verify
grep -n "InstalledVersions" vendor/composer/autoload_classmap.php

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

A globally installed tool still runs on a Composer 1 install

You seeThe project checks pass, but a command such as an installer you added with composer global require fails, and the stack trace points into the global Composer directory

Check

composer global manages a separate project under COMPOSER_HOME for CLI tools. Upgrading Composer does not rebuild that folder, so a tool installed there under Composer 1 keeps the old vendor layout.

Check
composer global config bin-dir --absolute

Fix

After moving Composer to 2.x, update the global project so its vendor folder and autoloader are rebuilt by the new version.

Fix
composer self-update --2
composer global update

Verify

The global tool starts without the class error.

Verify
composer global show

Confirmed by getcomposer.org

Did this fix it?

How do I stop it coming back?

  • Pin the Composer version used in CI and Docker builds, and print composer --version at the start of each job so a 1.x binary shows up in the log.
  • Build vendor/ once per release, with the same Composer that dumps the autoloader, instead of copying vendor folders between machines.
  • If your own package calls InstalledVersions, require composer-runtime-api ^2.0 in its composer.json, the way the runtime docs suggest for code that relies on these features.

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.

Which stack is behind this page?

Projects of mine on the same stack: Spotless Laundry, EZ Estimater.

Next step

Want this handled for good?

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