Doctrine\Common\Persistence\Mapping\Driver is missing
Asked Answered
W

1

5

Apologies but something weird has happened to me today with Symfony. I am developing a webapp with a friend and decided to run a composer update this morning. Everything was working correctly before, but once composer update finished I got a cache:clear error. It was about how Doctrine\Common\Persistence\ManagerRegistry; was not found on several repositories, so I tried to autocomplete with PhpStorm who could resolve to Doctrine\Persistence\ManagerRegistry all good. Problem is once I corrected that on all repositories I got the following error when trying to run php bin/console:

Symfony\Component\ErrorHandler\Error\ClassNotFoundError^ {#4524
  #message: """
    Attempted to load class "MappingDriverChain" from namespace "Doctrine\Common\Persistence\Mapping\Driver".\n
    Did you forget a "use" statement for "Doctrine\Persistence\Mapping\Driver\MappingDriverChain"?
    """
  #code: 0
  #file: "./var/cache/dev/ContainerO7VJLRg/App_KernelDevDebugContainer.php"
  #line: 1223
  trace: {
    ./var/cache/dev/ContainerO7VJLRg/App_KernelDevDebugContainer.php:1223 {
      ContainerO7VJLRg\App_KernelDevDebugContainer->getDoctrine_Orm_DefaultEntityManagerService($lazyLoad = true)^
      › 
      › $b = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
      › 
    }
    ./var/cache/dev/ContainerO7VJLRg/App_KernelDevDebugContainer.php:6427 { …}
    ./var/cache/dev/ContainerO7VJLRg/App_KernelDevDebugContainer.php:6472 { …}
    ./var/cache/dev/ContainerO7VJLRg/App_KernelDevDebugContainer.php:899 { …}
    ./vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php:90 { …}
    ./vendor/symfony/http-kernel/Kernel.php:572 { …}
    ./vendor/symfony/http-kernel/Kernel.php:131 { …}
    ./vendor/symfony/framework-bundle/Console/Application.php:168 { …}
    ./vendor/symfony/framework-bundle/Console/Application.php:74 { …}
    ./vendor/symfony/console/Application.php:140 { …}
    ./bin/console:42 { …}
  }
}

I shared it with my colleague who did not have the same issue. He ran composer update, and no issues at all on his side. So I just decided to push my changes to a different repository, and clone the project and try again. Same errors as before.

After that I decided to create a new symfony website from scratch and move the files over (after pulling his changes as well), (configs/src/templates/public etc) it worked like a charm, bin/console works perfectly, symfony server:start serves the page totally fine as well so we decided, cool let's move this into our shared repository, and he will try to clone it and run composer install.

As soon as he does, he gets exactly the same errors as me.

I tried cloning the project to another folder and exactly the same happened.

By the way, in spite of cache clear not working we are eliminating the cache folder at every single step.

I thought it would have something to do with symfony/orm-pack being updated to version 2.0.0 but we downgraded it and it didn't fix anything.

Symfony version (for both of us) is 5.1 additional libraries we are using are: data-dog/audit-bundle and ramsey/uuid-doctrine not sure if that helps.

Warrick answered 24/7, 2020 at 11:43 Comment(5)
What have you tried to debug the problem? Does the file in question exist?Shannonshanny
What we tried: 1 - create a new symfony project and move the files manually, which sorted the problem locally, but when we push these to git, and clone the project, as soon as we hit composer install or composer update the error is back 2- we tried it in windows and popOS, the same error occurs as soon as composer update or composer install are executed 3- we tried to downgrande symfony/orm-pack and the error persists The file in question does not exist, but it is not being used by the application's code, but from symfony's code itself on App_KernelDevDebugContainer.php.Warrick
If the file does not exist, have you tried checking for the reasons? It's part of doctrine/persistence - is that installed? Also, can you show the code triggering that error? As far as I see, the error message suggests a replacement, so maybe you are using the wrong namespace to load it?Shannonshanny
We are not loading it, symfony is, as you can see on the error posted above. Doctrine is being loaded as part of symfony/orm-pack. We can't update the namepsace on cache files generated by symfony, can we (if we can I will try that right away)? Adding to that if the error was on application side the website would not work after a fresh install of Symfony. We believe there is miss match between the libraries loaded by symfony, just not sure which. Any idea what library builds App_KernelDevDebugContainer?Warrick
It's Symfony itself that builds the container. So, you should start locating the error itself, for example by checking which service is called. It shouldn't be too hard to set a breakpoint in the container class to see what happens.Shannonshanny
W
7

Sorry for not replying earlier, but we found the error.

It had indeed to do with doctrine's version. On git we were passing the old composer.lock file while updating composer json hence why the error was coming back once we cloned it.

Basically, although we were specifying orm-pack's version 2.0.0 composer.lock was always limiting it to 1.8 and the namespaces and doctrine's folder structure changed between both versions.

once we erased composer.lock and updated composer everything worked fine.

Warrick answered 30/7, 2020 at 9:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.