2

I'm trying to install api-platform but I'm having problems after launching my composer install:

I follow the official docs for installation with:

composer req api

When I start the server or when I try to run composer install I get this error:

Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 255

and then a warning:

[WARNING] Some commands could not be registered:                               
!!                                                                                  
!!  
!!  In DoctrineOrmPropertyMetadataFactory.php line 31:
!!                                                                                 
!!    Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property  
!!    \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D  
!!    octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc  
!!    trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co  
!!    ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040                  
!!                                                                                 
!!  
!!  In DoctrineOrmPropertyMetadataFactory.php line 31:
!!                                                                                 
!!    Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property  
!!    \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D  
!!    octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc  
!!    trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co  
!!    ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040                  
!!                                                                                 
!!                                                                                  
!!   [WARNING] Some commands could not be registered:                               
!!                                                                                  
!!  
!!  In DoctrineOrmPropertyMetadataFactory.php line 31:
!!                                                                                 
!!    Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property  
!!    \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D  
!!    octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc  
!!    trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co  
!!    ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040                  
!!                                                                                 
!!  
!!  In DoctrineOrmPropertyMetadataFactory.php line 31:
!!                                                                                 
!!    Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property  
!!    \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D  
!!    octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc  
!!    trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co  
!!    ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040                  
!!                                                                                 
!!  
!!   // Clearing the cache for the dev environment with debug                       
!!   // true                                                                        
!!  
!!  
!!  In DoctrineOrmPropertyMetadataFactory.php line 31:
!!                                                                                 
!!    Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property  
!!    \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D  
!!    octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc  
!!    trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co  
!!    ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040                  
!!                                                                                 
!!  
!!  cache:clear [--no-warmup] [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
!!  
!!  2020-08-25T12:06:30+02:00 [critical] Uncaught Error: Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/ContainerPA69O1T/App_KernelDevDebugContainer.php on line 1040

Why am I getting this error, and what can I do to circumvent it?

MaxPtdr
  • 19
  • 3
  • Had you maybe been using an older version of Doctrine before and when you added the api library it updated it? Something similar happened here: https://stackoverflow.com/a/63188528/1196369 – mickadoo Aug 25 '20 at 10:30
  • You're not alone, they open an issue on [symfony's github](https://github.com/symfony/symfony/issues/37936) – rugolinifr Aug 25 '20 at 10:32

4 Answers4

1

NEWS : It Seems that adding these lines in your composer.json at the conflict property works !

"conflict": {
    "symfony/symfony": "*",
    "doctrine/common": ">=3.0",
    "doctrine/persistence": "<1.3"
},

So i got this problem since this morning and i looked for a solution and didn't found it so i made my own DIY solution and it's working Pretty find for me Then i'm gonna share it :

Firstly you need to go in the following path and open the file in it with your code editor:

C:\YOUR_PROJECT\vendor\api-platform\core\src\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory.php

Once you opened it, you need to REPLACE the line 19 (use Doctrine\Common\Persistence\ManagerRegistry;) with the following one:

use Symfony\Bridge\Doctrine\ManagerRegistry;

AND THAT'S ALL FOLKS ! SCREENSHOT OF THE LINE

PS: If you're still having issues or not founding the Vendor\api-platform, you just need to open the composer.json and temporary delete the Following line :

"cache:clear": "symfony-cmd",

And run again the command:

composer req api
0

we have the same problem since yesterday! I tried to change the version of the bundle, to an older version . But without any successful result.

Current dependency:

"api-platform/api-pack": "^1.2"

But the problem is solved on GitHub. To be tested... https://github.com/symfony/symfony/issues/37936


UPDATE: We have to wait for a release of api-platform bundle. https://github.com/api-platform/core/issues/3683

Maxime
  • 1
  • 4
0

Temporarily, you can add this to composer.json :

"conflict": {
    ...
    "doctrine/common": ">=3.0",
    "doctrine/persistence": "<1.3"
}

It works for me. https://github.com/api-platform/core/issues/3683#issuecomment-681039267

Maxime
  • 1
  • 4
0

I have the same problem but when i add the following lines

"conflict": { ... "doctrine/common": ">=3.0", "doctrine/persistence": "<1.3" } in my composer.json file the problem was resolved

Mousroot
  • 101
  • 3