Drupal 8 Upgrade Fails with Fatal error: ClassFinderInterface not found
Upgrades for Drupal 8 can sometimes go south rather badly and result in an error such as this:
Fatal error: Interface 'Doctrine\Common\Reflection\ClassFinderInterface' not found in /var/www/html/core/lib/Drupal/Component/Annotation/Reflection/MockFileFinder.php on line 14
I'm not PHP guy it took a while for me to unearth as the documents are thin and solutions vague. Googling it will suggest that the composer version is to, be blamed but adding to composer.json "doctrine/common":">2.8"
probably won't work, it didn't for me. I went on a wild multi-day adventure to solve this and the fix is actually pretty simple as it has to do with composer, the dependency manager for PHP. Rather than recount my frustrations with updater composer in my docker setup, I'll skip to the goods.
So here's the fix:
Note: If using docker, you'll need to docker exec bash into the container running PHP.
- Merge in the drupal updates from the Drupal repository
- Delete the
/vendor
directory and thecomposer.lock
file - Run
composer self-update
- optional add
"doctrine/common":">2.8"
to yourcomposer.json
. This may/may not be required - Run
composer update
to update all of Drupal's dependencies.
Troubleshooting
Problem
Running composer update
results in the long error message: [ErrorException] "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
or [ErrorException] "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
or it results in Fatal error: Uncaught Error: Class ‘Drupal\Composer\Plugin\Scaffold\Operations\AbstractOperation’ not found in /var/www/html/vendor/drupal/core-composer-scaffold/Operations/ReplaceOp.php:15
Solution
Delete the /vendor
and composer.lock