Fixing the Non-existent Service user.data Error

Sometimes, when upgrading or migrating a Drupal 8 or Drupal 9 site, a maddening error appears:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
The service "force_password_change.service" has a dependency on a
non-existent service "user.data". in
/home/mainacct/public_html/vendor/symfony/dependency-injection/$
on line 86 #0
/home/mainacct/public_html/vendor/symfony/dependency-injection/$
Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReference$
false)

The error message may mention different services, such as force_password_change.service or password_migrate .

Often this is caused by lurking problems with exported configuration definitions.

If you use Configuration Synchronization to export configuration information from one Drupal site to another, problems can pop up if you aren't careful about naming the export.

Once you apply the configurations to the second site, they can conflict with built-in functionality and cause errors.

Since the errors often don't appear until after you've cleared the cache - which could be hours or even weeks later, depending on your development schedule - it can be really difficult to figure out what's gone wrong.

Fortunately, a helpful discussion at StackExchange about "Non-existent service" errors after clearing the cache provides good clues about how to fix the situation:

Try moving the custom modules you created using Configuration Synchronization out of your modules directory.

For example, if you had placed your Configuration Synchronization modules in your web/modules/custom folder, just move them out of there into a temporary directory outside of your Drupal directory.

Then, clear the Drupal cache. The easiest way is to use drush:

drush cr

Then try reloading your page. With luck, the error message will be gone, and your site will be working again.

 

 

Image by Mikhail Nilov.