skip to Main Content

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 AppEntityToken.
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: 'AppEntity'

3

Answers


  1. 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
    
    Login or Signup to reply.
  2. It will not be the exact answer to your question, but my advice is to move PHP 8.1 attributes instead of doctrine annotations.

    Trying to install doctrine/annotations, which will require version 2.0 gave me conflicts with other tools that required version 1.x.

    Set your Symfony DoctrinBundle mapping type to attribute

    doctrine:
        dbal:
            url: '%env(resolve:DATABASE_URL)%'
    
        form:
            ...
            mappings:
                App:
                    is_bundle: false
                    type: attribute
    

    More info about the attribute settings can be found here:

    https://www.doctrine-project.org/projects/doctrine-orm/en/2.14/reference/attributes-reference.html

    Login or Signup to reply.
  3. You should use PHP 8 attributes for routing annotations instead of use deprecated doctrine/annotations package as noted in their deprecation notice : https://www.doctrine-project.org/projects/doctrine-annotations/en/2.0/index.html#deprecation-notice

        PHP 8 introduced attributes, which are a native replacement for annotations. 
        As such, this library is considered feature complete, 
        and should receive exclusively bugfixes and security fixes.
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search