I get the following error when running bin/magento setup:di:compile:

Errors during configuration scanning:
                Invalid Factory for nonexistent class IntegerNet\SolrSuggest\Implementor\Factory\App in file [...]/vendor/integer-net/solr-magento2/src/Model/Cache.php

The AppFactory is actually a real interface from a library, it should not be generated by Magento. As far as I understood the generation, factories are only generated if the class does not exist. I double checked that the file exists and the directory is registered in vendor/composer/autoload_psr4.php.

This is how the class that depends on the factory looks like:


namespace IntegerNet\Solr\Model;
use IntegerNet\SolrSuggest\Implementor\Factory\AppFactory;
class Cache
     * @var AppFactory
    private $appFactory;
    public function __construct(AppFactory $appFactory)
        $this->appFactory = $appFactory;

And this is the factory:


namespace IntegerNet\SolrSuggest\Implementor\Factory;
use IntegerNet\SolrSuggest\Implementor\Factory\CacheWriterFactory;
use IntegerNet\SolrSuggest\Implementor\Factory\ConfigFactory;
interface AppFactory extends ConfigFactory, CacheWriterFactory

I defined a preference for the interface in di.xml:

<preference for="IntegerNet\SolrSuggest\Implementor\Factory\AppFactory" type="IntegerNet\Solr\Model\Bridge\AppFactory" />

Any idea what I can do about these messages?


In developer mode where I don't explicitly run the compile command, I don't get any errors. And although I get these error messages, compilation runs through and everything works - which proves that the factory classes can be used.


3 Answers 3


That's an interesting issue and I'm not entirely sure why is this happening.

What I can suggest is debugging directly in the _findMissingClasses method from Magento/Setup/Module/Di/Code/Scanner/PhpScanner that's where the error is coming from:

protected function _findMissingClasses($file, $classReflection, $methodName, $entityType)
    $missingClasses = [];
    if ($classReflection->hasMethod($methodName)) {
        $constructor = $classReflection->getMethod($methodName);
        $parameters = $constructor->getParameters();
        /** @var $parameter \ReflectionParameter */
        foreach ($parameters as $parameter) {
            preg_match('/\[\s\<\w+?>\s([\w\\\\]+)/s', $parameter->__toString(), $matches);
            if (isset($matches[1]) && substr($matches[1], -strlen($entityType)) == $entityType) {
                $missingClassName = $matches[1];
                try {
                    if (class_exists($missingClassName)) {
                } catch (\RuntimeException $e) {
                $sourceClassName = $this->getSourceClassName($missingClassName, $entityType);
                if (!class_exists($sourceClassName) && !interface_exists($sourceClassName)) {
                        "Invalid {$entityType} for nonexistent class {$sourceClassName} in file {$file}"
                $missingClasses[] = $missingClassName;
    return $missingClasses;

That method is called from the _fetchFactories method which also logs the same error so you need to find out, where the error is coming from exactly and from there you should be able to start debugging:

protected function _fetchFactories($reflectionClass, $file)
    $factorySuffix = '\\'.ucfirst(FactoryGenerator::ENTITY_TYPE);
    $absentFactories = $this->_findMissingClasses(
    foreach ($absentFactories as $key => $absentFactory) {
        if (substr($absentFactory, -strlen($factorySuffix)) == $factorySuffix) {
            $entityName = rtrim(substr($absentFactory, 0, -strlen($factorySuffix)), '\\');
                'Invalid Factory declaration for class ' . $entityName . ' in file ' . $file
    return $absentFactories;

Taking @Raphael's suggestion, I looked through Magento/Setup/Module/Di/Code/Scanner/PhpScanner::_findMissingClasses with the debugger on, the issue arises from this block of code

if (class_exists($missingClassName)) {

In your case @fschmengler $missingClassName is IntegerNet\SolrSuggest\Implementor\Factory\AppFactory which as you said is an interface not a class.

Revising the core code to

if (interface_exists($missingClassName) || class_exists($missingClassName)) {

seems to eliminate the problem. Maybe this is a bug worth mentioning to the Magento developers?


I had similar errors

Interception cache generation... 6/9 [==================>---------]  66% 58 secs 442.0 MiBErrors during configuration scanning:
                Invalid Factory for nonexistent class Magento\Company\Api\Data\CompanyInterface in file /home/companyde/staging-m2.company.de/setup/src/Magento/Setup/Fixtures/CompaniesFixture.php
                Invalid Factory for nonexistent class Magento\NegotiableQuote\Model\NegotiableQuote in file /home/companyde/staging-m2.company.de/setup/src/Magento/Setup/Fixtures/NegotiableQuotesFixture.php
                Invalid Factory for nonexistent class Magento\Company\Model\ResourceModel\Company\Collection in file /home/companyde/staging-m2.company.de/setup/src/Magento/Setup/Fixtures/NegotiableQuotesFixture.php
                Invalid Factory for nonexistent class Magento\NegotiableQuote\Api\Data\HistoryInterface in file /home/companyde/staging-m2.company.de/setup/src/Magento/Setup/Fixtures/NegotiableQuotesFixture.php
                Invalid Factory for nonexistent class Magento\SharedCatalog\Model\ResourceModel\SharedCatalog\Collection in file /home/companyde/staging-m2.company.de/setup/src/Magento/Setup/Fixtures/SharedCatalogsFixture.php
Total Errors Count: 5

I solved these errors by deleting the following files:


I think these files are from magento enterprise B2B module. I removed the module with composer remove but the files where not deleted as well and caused the error.

  • ➕ similar experience. Running composer install, bin/magento c:c, and bin/magento set:up resolved this issue for me.
    – Mike Dubs
    Commented Nov 15, 2022 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.