magento2: App\ResourceConnection\Proxy does not exist

each time i run the the below command

bin/magento setup:di:compile

the response is Class Magento\Framework\App\ResourceConnection\Proxy does not exist

after that, all magento cli commands shows me the same error!!!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 27 (10 by maintainers)

Most upvoted comments

Thanks to the accurate explanation of @PascalBrouwers about how to reproduce it, I’d like to share here my findings.

TL;DR

This issue only seems to happen when:

  • PSR-0 autoload configuration includes generated/code/

  • generated/code/ folder is not empty and has generated code, due to automatic generation, setup:di:compile, or deploy:mode:set production

Error occurs when autoload classmap is generated using existing generated/code/ files, and then files under generated/code/ are removed (See full explanation for further details).

There are some ways to get rid of this behaviour. You can either (please note this options are mutually exclusive):

  • Run bin/magento deploy:mode:set developer prior to composer install --optimize-autoloader to get generated/code/ folder files cleared (You may want to rerun composer dump-autoload --optimize after compilation to get classmap files updated)

  • Run rm -rf generated/code/ to erase manually generated/code/ folder files prior to composer install --optimize-autoloader to get generated/code/ folder files cleared (You may want to rerun composer dump-autoload --optimize after compilation to get classmap files updated)

  • Run rm -f var/.regenerate to erase manually regenerate flag, avoiding generated/code/ being cleared at the start of any Magento request, including cli ones, between composer install --optimize-autoloader and bin/magento command:

composer install --optimize-autoloader
rm -f var/.regenerate
bin/magento list
  • Change the process strategy as follows:

    • Update your composer.json, config section, define "optimize-autoloader": false, so autoloader optimization does not occur unless explicitly set in composer install / dump-autoload commands options
    • Run composer install without --optimize-autoloader flag
    • Do your work, possibly compiling files via setup:di:compile or similar
    • When your application has reached the desired state, run composer dump-autoload --optimize to generate classmap with all generated files

Full Explanation

Magento has a cleanup system that tries to detect when generated code and cache needs to be refreshed, upon installation / uninstallation of Composer packages. Whenever changes are detected, a file flag is created: var/.regenerate (please note this is not the same file as var/.regenerate.lock). At an very early stage of any Magento related code execution, the existence of this flag is checked, and if it exists, \Magento\Framework\Code\GeneratedFiles::cleanGeneratedFiles is called, so generated/code/ files are deleted and expected to be regenerated dynamically.

The issue here is that magento/magento-composer-installer Composer plugin fails to detect properly when there are actual changes in packages (see \MagentoHackathon\Composer\Magento\Plugin::onNewCodeEvent), and it sets var/.regenerate flag after each Composer install / update operation (post-install-cmd / post-update-cmd events), regardless if any package has been installed or removed. It also does not take care of --optimize-autoloader flags, or any flag at all.

Taking the provided replication example, process sequence is as follows (assuming existing files under generated/code/ folder, see preconditions above):

1. composer install --optimize-autoloader

  • Operation installs packages or not, it does not matter.
  • vendor/composer/autoload_classmap.php is generated, referencing existing files under generated/code/ due to PSR-0 directive.
  • magento/magento-composer-installer sets request regeneration flag var/.regenerate

2. bin/magento list (Fails)

  • Due to var/.regenerate existing, just after execution start, generated/code/ files are deleted. Classmap under vendor/composer/autoload_classmap.php is not valid anymore, at least for those referencing generated/code/ files.
  • Request execution resumes
  • Request fails to proceed properly, failing when it first references a just deleted class under generated/code/ (in this case Magento\Framework\App\ResourceConnection\Proxy, but it could be another one, problem is not really in that concrete class).

3. composer install --optimize-autoloader

  • Operation installs packages or not, it does not matter.
  • vendor/composer/autoload_classmap.php is generated, with a difference from first time it was executed: as in previous bin/magento list command the generated/code/ files were deleted due to regeneration request caused from 2 commands above, no references to generated/code/ files are generated in classmap.
  • magento/magento-composer-installer sets request regeneration flag var/.regenerate

4. bin/magento list (Succeeds)

  • Due to var/.regenerate existing, just after execution start, generated/code/ files are deleted. Classmap under vendor/composer/autoload_classmap.php is still valid, as it does not reference any file under generated/code/. Due to classmap check miss, Composer fallbacks to look for the file and class, and Magento code generator system generates non-existing classes, filling up again generated/code/.
  • Request execution resumes and succeeds.

At this point, you are at the start point, with files under generated/code/, and can indefinitely run this four steps loop with same results (1 OK, 1 KO, 1 OK, 1 KO…).

I have the same problem right after composer install. I have changed job company, workstation, project and this error is not absent. So, I can suppose that problem in magento.

But, running a

bin/magento c:f
composer install --optimize-autoloader

Again after that and the error is back again

To recap:

bin/magento c:f
composer install --optimize-autoloader
bin/magento -> here I get the error
composer install --optimize-autoloader
bin/magento -> everything fine again

bin/magento c:f
composer install --optimize-autoloader
bin/magento -> there is that error again

Able to reproduce by:

bin/magento c:f
composer install --optimize-autoloader
bin/magento

Gives Class Magento\Framework\App\ResourceConnection\Proxy does not exist Strangely enough running composer install again after the error seems to resolve it. Somehow it needs the error.

I have closed this, because i cant regenerate it again.

Lol - why was this closed without comment? Seems to be a legit issue.

@khanzadimahdi mostly this issues occur due to miss configuration of your folder users permission by permission i mean “Owner” and “Group” e.g if your server using owner as “root” and group as “root” also and your files and folder user owner as “user” and group as “server” so you will face this error Class Magento\Framework\App\ResourceConnection\Proxy does not exist

Conclusion your “owner” and “group” needs to be match with server.

I also experienced this issue after a clean install of Magento 2.3.6 using Composer 1.10.13, and running bin/magento list.

The fix, in my case, was to reset permissions of the Magento root folder which was done using the following commands:

cd /var/www/html/magento2
sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
sudo chown -R :www-data .
sudo chmod u+x bin/magento

This code snippet is referenced in the Magento Docs. You can also check these links for a better understanding of the commands: How to use the chmod command and Understanding the exec option of find.

@travis-st okay i reopen it for you.