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)
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, ordeploy:mode:set productionError occurs when autoload classmap is generated using existing
generated/code/files, and then files undergenerated/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 developerprior tocomposer install --optimize-autoloaderto getgenerated/code/folder files cleared (You may want to reruncomposer dump-autoload --optimizeafter compilation to get classmap files updated)Run
rm -rf generated/code/to erase manuallygenerated/code/folder files prior tocomposer install --optimize-autoloaderto getgenerated/code/folder files cleared (You may want to reruncomposer dump-autoload --optimizeafter compilation to get classmap files updated)Run
rm -f var/.regenerateto erase manually regenerate flag, avoidinggenerated/code/being cleared at the start of any Magento request, including cli ones, betweencomposer install --optimize-autoloaderandbin/magentocommand:Change the process strategy as follows:
"optimize-autoloader": false, so autoloader optimization does not occur unless explicitly set in composer install / dump-autoload commands optionscomposer installwithout--optimize-autoloaderflagsetup:di:compileor similarcomposer dump-autoload --optimizeto generate classmap with all generated filesFull 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 asvar/.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::cleanGeneratedFilesis called, sogenerated/code/files are deleted and expected to be regenerated dynamically.The issue here is that
magento/magento-composer-installerComposer plugin fails to detect properly when there are actual changes in packages (see\MagentoHackathon\Composer\Magento\Plugin::onNewCodeEvent), and it setsvar/.regenerateflag after each Composer install / update operation (post-install-cmd/post-update-cmdevents), regardless if any package has been installed or removed. It also does not take care of--optimize-autoloaderflags, 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-autoloadervendor/composer/autoload_classmap.phpis generated, referencing existing files undergenerated/code/due to PSR-0 directive.magento/magento-composer-installersets request regeneration flagvar/.regenerate2.
bin/magento list(Fails)var/.regenerateexisting, just after execution start,generated/code/files are deleted. Classmap undervendor/composer/autoload_classmap.phpis not valid anymore, at least for those referencinggenerated/code/files.generated/code/(in this caseMagento\Framework\App\ResourceConnection\Proxy, but it could be another one, problem is not really in that concrete class).3.
composer install --optimize-autoloadervendor/composer/autoload_classmap.phpis generated, with a difference from first time it was executed: as in previousbin/magento listcommand thegenerated/code/files were deleted due to regeneration request caused from 2 commands above, no references togenerated/code/files are generated in classmap.magento/magento-composer-installersets request regeneration flagvar/.regenerate4.
bin/magento list(Succeeds)var/.regenerateexisting, just after execution start,generated/code/files are deleted. Classmap undervendor/composer/autoload_classmap.phpis still valid, as it does not reference any file undergenerated/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 againgenerated/code/.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
Again after that and the error is back again
To recap:
Able to reproduce by:
Gives
Class Magento\Framework\App\ResourceConnection\Proxy does not existStrangely enough runningcomposer installagain 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:
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.