PHP cannot find Composer\InstalledVersions at runtime
Fix it fast
Most common cause, 1 of 3Composer 1 installed the project's vendor folder
Move the binary to the 2.x channel, then build vendor/ again from the lock file.
composer self-update --2
rm -rf vendor
composer installShort 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.
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.
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:
- 1Composer 1 installed the project's vendor folder
composer --version prints 1.x, and vendor/composer/InstalledVersions.php does not exist - 2The autoload files were dumped by an older Composer than the packages
InstalledVersions.php exists in vendor/composer, yet autoload_classmap.php has no line for it - 3A globally installed tool still runs on a Composer 1 install
The 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 foundClass '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.
composer --versionFix
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.
composer self-update --2
rm -rf vendor
composer installVerify
The class file is present and the one-line PHP check prints bool(true).
php -r 'require "vendor/autoload.php"; var_dump(class_exists("Composer\\InstalledVersions"));'Confirmed by getcomposer.org
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.
grep -c "InstalledVersions" vendor/composer/autoload_classmap.phpFix
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.
composer --version
composer dump-autoload --optimizeVerify
grep now counts at least one match, and the page or command that failed loads.
grep -n "InstalledVersions" vendor/composer/autoload_classmap.phpConfirmed by raw.githubusercontent.com
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.
composer global config bin-dir --absoluteFix
After moving Composer to 2.x, update the global project so its vendor folder and autoloader are rebuilt by the new version.
composer self-update --2
composer global updateVerify
The global tool starts without the class error.
composer global showConfirmed by getcomposer.org
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.