Maaz Zindani

Loading the index…

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

Composer stops because a classmap path is missing on disk

Your error

Could not scan for classes inside "app/database/migrations" which does not appear to be a file nor a folder1 more line it can show

Fix it fast

Most common cause, 1 of 4

A folder or file listed under classmap was renamed, moved or deleted

Change the entry to the folder's new location, or delete the entry if nothing there needs scanning, then rebuild the autoloader.

Fix
"autoload": {
    "classmap": ["lib/legacy"]
}

composer dump-autoload
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Composer 2 scans every path listed under classmap and fails with could not scan for classes when one is neither a file nor a folder. The path names the case: a stale entry in composer.json, an empty folder Git never committed, an autoload-dev path missing in production, or an incomplete package in vendor. Fix the path and rebuild the autoloader.

  • Applies to Composer 2.11, PHP 8.3, PHP 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Take the path from the message and look for it in composer.json, then check whether it exists. A path that begins with vendor/ belongs to a package, not to your project.

Run this first
grep -n -B2 -A8 '"classmap"' composer.json
ls -ld app/database/migrations

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

  1. 1A folder or file listed under classmap was renamed, moved or deletedThe path is in your own composer.json, and ls reports No such file or directory
  2. 2The folder is empty on your machine, so Git never stored itWorks on your laptop, fails right after a fresh git clone on the server or in CI
  3. 3An autoload-dev path is missing from the production copyThe path is a tests or fixtures folder, and the deploy leaves that folder out (an rsync exclude, a .dockerignore line or an export-ignore rule)
  4. 4A package in vendor is missing part of its filesThe path in the message starts with vendor/, such as vendor/acme/foo/tests/Fixtures

What does the error look like?

  • Could not scan for classes inside "app/database/migrations" which does not appear to be a file nor a folder
  • The message appears at the end of composer install or composer update, or on composer dump-autoload

Cause 1 of 4

A folder or file listed under classmap was renamed, moved or deleted

You seeThe path is in your own composer.json, and ls reports No such file or directory

Check

Could not scan for classes inside a path taken from your own composer.json means a classmap entry points at a folder or file that was moved or deleted. Composer reads every directory and file in the classmap list and scans its .php and .inc files; its class map generator throws this exact error when an entry is neither an existing file nor a directory (entries containing a * wildcard are exempt).

Check
grep -n -A8 '"classmap"' composer.json
for p in app/database/migrations app/database/seeds; do ls -ld "$p"; done

Fix

Change the entry to the folder's new location, or delete the entry if nothing there needs scanning, then rebuild the autoloader.

Fix
"autoload": {
    "classmap": ["lib/legacy"]
}

composer dump-autoload

Verify

dump-autoload runs to the end without a RuntimeException.

Verify
composer dump-autoload

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 4

The folder is empty on your machine, so Git never stored it

You seeWorks on your laptop, fails right after a fresh git clone on the server or in CI

Check

Could not scan for classes right after a fresh clone, while your own copy works, means the classmap folder is empty and was never committed. Git's index only lists files; a directory is not tracked on its own and appears in a checkout only when a file inside it is committed. An empty migrations or seeds folder therefore exists locally but not in the clone.

Check
git ls-files app/database/seeds | head
git clone . /tmp/clone-check && ls -ld /tmp/clone-check/app/database/seeds

Fix

Commit a placeholder file in the folder, as the Git FAQ suggests for a directory that must exist in checkouts, or drop the entry from classmap if the folder will stay empty.

Fix
touch app/database/seeds/.gitkeep
git add app/database/seeds/.gitkeep
git commit -m "Keep seeds folder for the classmap"

Verify

A new clone contains the folder and composer install runs to the end.

Verify
git ls-files app/database/seeds

Confirmed by archive.kernel.org

Did this fix it?

Cause 3 of 4

An autoload-dev path is missing from the production copy

You seeThe path is a tests or fixtures folder, and the deploy leaves that folder out (an rsync exclude, a .dockerignore line or an export-ignore rule)

Check

Could not scan for classes on a production server, for a tests or fixtures path, means Composer is applying autoload-dev rules to a copy that left those folders out. Rules under autoload-dev are meant for development only; when the deploy drops a classmap folder listed there but Composer still runs in development mode, it tries to scan that folder and fails.

Check
grep -n -A8 '"autoload-dev"' composer.json

Fix

Install in production with --no-dev. Composer then skips the require-dev packages and also leaves the autoload-dev rules out of the generated autoloader.

Fix
composer install --no-dev

Verify

The production install completes, and a later dump keeps the dev rules out explicitly.

Verify
composer dump-autoload --no-dev

Confirmed by getcomposer.org

Did this fix it?

Cause 4 of 4

A package in vendor is missing part of its files

You seeThe path in the message starts with vendor/, such as vendor/acme/foo/tests/Fixtures

Check

Could not scan for classes inside a vendor/ path means the classmap belongs to a dependency whose files on disk are incomplete. A dependency's classmap is resolved inside that package's folder, so a package with missing files (an interrupted install, a copied vendor folder, a cleanup script) triggers the same error. Compare the folder with what the package should contain.

Check
ls -la vendor/acme/foo/

Fix

Reinstall the package, or rebuild vendor from the lock file, which installs the exact locked versions again.

Fix
composer reinstall acme/foo
# or, for the whole tree
rm -rf vendor && composer install

Verify

The path from the message now exists inside vendor and the install ends cleanly. If a clean reinstall still lacks it, the package's own release leaves that folder out and the fix belongs to its maintainers.

Verify
ls -ld vendor/acme/foo/tests/Fixtures

Confirmed by getcomposer.org

Did this fix it?

How do I stop it coming back?

  • After moving or renaming any folder named under classmap, update composer.json and run composer dump-autoload in the same commit.
  • For code you own, map namespaces with psr-4 instead of listing folders one by one.
  • Keep tests and fixtures under autoload-dev and deploy with composer install --no-dev.
  • Let CI run composer install from a fresh clone, so a directory present on just one developer machine breaks the build before it breaks a deploy.

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.