cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 compiling issue | Requested class did not generate properly

Magento 2 compiling issue | Requested class did not generate properly

Firstly let me mention I'm not very good with magento but managing it for about 3 years I know a few things.

 

Issue is that the content of generated dir does not generate properly on compile because of some error in old file(s). As you can see compile gets stuck on 50% as shown in image below.

If I delete the content in generated it gets populated again after a few seconds because of cron maybe idk. Like if I deleteit, it get deleted but reappears after a few seconds. As to my understanding there are some files missing when content is populated/generated by cron which is basically causing the actual error.

 

below image shows what happens when I try to compile

rhUjC

 

there is no cron running by magento user as I deleted it, instead someone ran cron by root a while ago which is running I think. I tried to remove cron created by root but I am unable to remove it. 

When cron generates the dir "code", inside "generated" some of dir and files inside "code" are owned by root including composer and a few extensions. Rest of the web root is set to www-data:www-data.

Please let me know if these is something you guys can suggest to fix it.

 

#~ MAGENTO START 40d1b2d83998fabacb726e5bc3d22129



* * * * * /usr/bin/php7.1 /var/www/html/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/var/log/magento.cron.log



* * * * * /usr/bin/php7.1 /var/www/html/update/cron.php >> /var/www/html/var/log/update.cron.log



* * * * * /usr/bin/php7.1 /var/www/html/bin/magento setup:cron:run >> /var/www/html/var/log/setup.cron.log



#~ MAGENTO END 40d1b2d83998fabacb726e5bc3d22129

Not sure how to remove it now, tried bin/magento cron:remove

Tried crontab -e and commenting it out

5 REPLIES 5

Re: Magento 2 compiling issue | Requested class did not generate properly

@w3_Shaheer 

 

While compiling if you are facing error, then it should not be linked to your cron, can you share the error you are getting ?

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

Re: Magento 2 compiling issue | Requested class did not generate properly

Hi @w3_Shaheer 

 

As attached error image showing, there is some permission issue with generated folder.
So please assign permission to generated folder first then run compile command or you can follow below command:

sudo chmod -R 777 var/ pub/ generated/
php bin/magento setup:di:compile

It may help you!
Problem Solved? Please click on 'Kudos' & Accept as Solution!

Problem solved? Click Accept as Solution!

Re: Magento 2 compiling issue | Requested class did not generate properly

Yes it shouldn't be related to cron but in my case there is already an issue, which is a missing file inside generated folder, to fix that I can delete everything inside generated and recompile, that's where cron is relevant, I can delete everything in generated but it gets populated again after a few seconds, and I am guessing it's because of cron, what else can cause it to reappear again except cron, right? 

 

basic error is just that my compiling gets stuck on 50% as shown in photo I have attached in question. 

Re: Magento 2 compiling issue | Requested class did not generate properly

From the image it looks like you are running bin/magento command as sudo. That is not recommended and probably what is causing your root/permission problem?

Have you tried without sudo/are you running command as the magento file system owner?

See this doc for information on permissions

https://devdocs.magento.com/guides/v2.4/install-gde/prereq/file-sys-perms-over.html

Re: Magento 2 compiling issue | Requested class did not generate properly

Yes you are right I also think problem might be permission of user.

 

One more thing I have tried to run commands without sudo but they get denied every time, why is that exactly if you can explain.

 

User shaheer is member of following groups "shaheer, root, sudo, www-data, lxd" magento files are owned by www-data www-data but files inside generated/code are owned by root root, no matter how many times I fix it, it goes back it root again. it's probably because of sudo, I know I am not meant to use commands as sudo but I get permission denied without sudo so can you tell me what mistake I'm making here when it comes to user permissions.

 

One more thing if I have two users, root for server files and another for magento files should I be using "Production file system ownership for private hosting (two users)" as mentioned here https://devdocs.magento.com/guides/v2.3/config-guide/prod/prod_file-sys-perms.html

 

Thank you so much