What to do with Drupal 8's "Class not found" errors?

Cache rebuild

As usual with Drupal, first thing to try is always cache rebuild:

drupal cache-rebuild

If it didn't help, try once again. Just in case. You know, it's Drupal after all.

Restart the web server

In addition to the usual cache rebuild, the additional need to restart the web server is due to a decision in Drupal 8 to be "fast by default" and use the APC Classloader if it is available. It is faster, but it doesn't necessarily catch changes as you make them.

Disable APC Classloader for local install

To not have to restart your web server during development, you can set your local environment to not try to use a better-for-production class loader.

For instance, in your local.settings.php add:

$settings['class_loader_auto_detect'] = FALSE;

How to clear APC cache entries?

Clear APC system cache:


To clear APC user cache:


Note that to be able to do this via command line you need to edit your apc.ini and add there:


This however will not work when running Apache in mod_php mode, as in such a case Apache APC cache and CLI cache use completely separate processes.

Composer Merge Plugin

Try using the Composer Merge Plugin:

composer require wikimedia/composer-merge-plugin

and then in your root composer.json:

  "extra": {
    "merge-plugin": {
      "include": [
      "recurse": true,
      "replace": false,
      "merge-extra": false