Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force composer dump-autoload to start from scratch?

What is the exact set of files that I should manually delete in order to make sure that a subsequent invocation of composer dump-autoload will behave EXACTLY as it would in a virgin freshly cloned composer project that was just composer installed, but never previously dump-autoloaded?

I am trying to reproduce and debug a problem that occurs during composer dump-autoload command executed as part of a docker image build.

I want to avoid the slowness of actually running a docker build dozens of times during the iterative process of finding the solution.

Deleting the entire vendor/ directory and redoing composer install every time is also suboptimal.

like image 423
Szczepan Hołyszewski Avatar asked Sep 19 '25 20:09

Szczepan Hołyszewski


1 Answers

It always runs from "scratch". But I guess that if you want to be extra sure, you can simply delete the previously generated files.

The created files are vendor/autoload.php and some on vendor/composer, so you could delete them manually before re-dumping the autoloader.

These are the contents of that directory fresh out of a composer install --no-autoloader:

└── vendor/
   └── composer/
      ├── semver/
      ├── xdebug-handler/
      ├── installed.json
      └── LICENSE

And these are its contents after running composer dump-autoload:

├── vendor/
│   └── composer/
│      ├── semver/
│      ├── xdebug-handler/
│      ├── autoload_classmap.php
│      ├── autoload_files.php
│      ├── autoload_namespaces.php
│      ├── autoload_psr4.php
│      ├── autoload_real.php
│      ├── autoload_static.php
│      ├── installed.json
│      └── LICENSE
└── autoload.php

So you basically need just to delete

  • vendor/autoload.php
  • vendor/composer/autoload_*
  • vendor/composer/ClassLoader.php

And you can rerun composer dump-autoload from a pristine starting point.

like image 154
yivi Avatar answered Sep 21 '25 14:09

yivi