Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency on a non-existent service "doctrine.orm.metadata.annotation_reader"

So I have a Symfony 6.2 API, PHP 8.2 codebase.

While trying to run composer install/update the following error is displaying and I'm wondering how to clear it:

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 83:
The service "doctrine.orm.default_annotation_metadata_driver" has a dependency 
on a non-existent service "doctrine.orm.metadata.annotation_reader".

If I comment out the mappings section in doctrine.yaml file (below) composer runs successfully, however all POST requests to the api will then result in the following error:

Could not find the entity manager for class App\Entity\Token.
Check your Doctrine configuration to make sure it is configured 
to load this entity’s metadata. (500 Internal Server Error)

Scratching my head here to understand how to resolve it. I've a feeling it may be doctrine.yaml related but I could be miles off the mark.

composer.json:

"require": {
        "php": ">=8.2",
        ...
        "doctrine/doctrine-bundle": "^2.8",
        "doctrine/doctrine-migrations-bundle": "^3.2",
        "doctrine/orm": "^2.14",
        ...
    },

doctrine.yaml:

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'

    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
like image 876
Donal.Lynch.Msc Avatar asked Sep 07 '25 12:09

Donal.Lynch.Msc


2 Answers

You are missing the doctrine/annotationsdependency. Try to add in your composer.json file:

"doctrine/annotations": "^1.0",

Then run composer update. Or just run:

composer require doctrine/annotations
like image 166
COil Avatar answered Sep 09 '25 03:09

COil


In symfony 6.4 and up, if you get non-existent service "annotation_reader". errors,

you may need to remove annotations: false from config/packages/framework.yaml.

like image 31
Simon Epskamp Avatar answered Sep 09 '25 01:09

Simon Epskamp