I have added a Repository interface in my Api directory and it's implementation in located under Models directory.

I have setup the preference for the interface in etc/di.xml.

When I run bin/magento setup:di:compile the following error is thrown in the console.

Source class "\Namespace\Module\Model\PostInterface" for "Namespace\Module\Model\PostRepository" generation does not exist.

I have no idea why the system is searching for "\Namespace\Module\Model\PostInterface" while I have mentioned clearly the location of the implementation class in di.xml.

Any suggestions are welcome with thanks !!

More Info:

When I remove the Repository implementation file i.e; app/code/Namespace/Module/Model/PostRepository.php (imlpements app/code/Namespace/Module/Api/PostRepositoryInterface.php), the error disappears.

Also, when I rename the file from app/code/Namespace/Module/Model/PostRepository.php to app/code/Namespace/Module/Model/PostRepositoryy.php, the error disappears.

Is there any conventions that needs to be followed while using Repositories ?

  • I get the same error and removing or renaming the file does not help. It's crazy. Sep 18, 2017 at 15:25

5 Answers 5


After a lot of Code analysis and Google searches, I found the fix for this problem. Adding the following to the di.xml fixed this issue.

<type name="Magento\Framework\Model\Entity\RepositoryFactory">
            <argument name="entities" xsi:type="array">
                <item name="Namespace\Module\Api\Data\PostInterface" xsi:type="string">Namespace\Module\Api\Data\PostRepositoryInterface

Remove var/generation and var/di folders Then try again with command

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy
  • I have followed these steps and the error still appears. Mar 23, 2017 at 6:46

I had this issue with a custom module, it was a typo in the composer here:"autoload": { "files": [ "registration.php" ], "psr-4": { "Vendor\\Namespace\\": "" } } in the vendor\namespace. Might be useful for others.


This is an old post now, but for anyone else that's still experiencing this, a fix that seems to work is rather than defining the repository interface as a use statement, add its fully qualified name, for example:

use Vendor\Module\Interface;

class MyClass implements Interface


class MyClass implements \Vendor\Module\Interface

This fixed this for us when compiling repositories on M2 2.2.3


I've had this error after trying to generate di and it even persisted on any cli command for some reason.

Try to delete generated/*

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.