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.

  1. Merge in the drupal updates from the Drupal repository
  2. Delete the /vendor directory and the composer.lock file
  3. Run composer self-update
  4. optional add "doctrine/common":">2.8" to your composer.json. This may/may not be required
  5. 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