I am running drush first time in my Drupal 9 project and getting the following error

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:

  The service "sanitize.userfields.commands" has a dependency on a non-existent service "entity.manager".  

Is there anything I have missed? I was trying to list all available commands. After @hurdi's cooment I found drush --version drush cr are working.

Note: It is my first Drupal setup and I'm learning it.

  • 1
    At first glance looks like an outdated version of Drush, not compatible with Drupal v9. Try to upgrade – Hudri Jun 19 at 5:57
  • Currently, it is Drush Commandline Tool 10.0.3-dev – Codesigner Jun 19 at 6:03
  • 1
    What command? A command provided by a module? Looks like it's not D9 ready. Can it be updated? It must have entity type manager instead. Can easily be fixed. – leymannx Jun 19 at 7:16
  • updated the question, drush was installed with drupal itself. Should we update it? How? – Codesigner Jun 19 at 8:02
  • @hurdi and leymannx, upvoting you as it is solved by upgrading. – Codesigner Jun 19 at 14:44

As folks (Hudri, leymannx) alluded to in the comments, entity.manager was deprecated in Drupal 8 which means it was removed in Drupal 9. The project that has the code that's calling entity.manager is not ready for Drupal 9 (or at least the version you have installed is not ready for Drupal 9). You may want to look for alternative modules if the one your using isn't ready for Drupal 9.

This one particular error is relatively simple to fix though, you should just need to replace any references to entity.manager with references to entity_type.manager. This issue on d.o gives a good example of what you may have to do.

Note: if this issue is being caused by a contributed package, e.g. a d.o module or theme or other package included by composer, you need to work within that project's issue queue to patch the project instead of updating the files directly in your codebase. At the very least, you'll want to create a local patch in your composer project and configure composer to apply the patch.

| improve this answer | |
  • thanks for explaining possible scenarios, upvoting you. – Codesigner Jun 19 at 14:42

Seems like Drush which came with the setup was not fully compatible. I installed it again using the composer using

composer require drush/drush

It is working as expected.

Here is updated "require" section looks like in composer.json

   "require": {
        "composer/installers": "^1.9",
        "drupal/bootstrap_barrio": "^4.28",
        "drupal/bootstrap_sass": "^1.12",
        "drupal/core-composer-scaffold": "^9",
        "drupal/core-project-message": "^9",
        "drupal/core-recommended": "^9",
        "drush/drush": "^10.2"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.