There is no di folder generated in var directory. I am getting please re-run compile command. Why we need this di directory?

4 Answers 4


If you have upgraded to Magento version 2.2.* then

var/generation has been moved to generated/code


var/di has been moved to generated/metadata

There shouldn't be var/di and var/generation folders after the upgrade.


di folder are generate at compile time inside var folder.

remove content of generation folder. if di folder is not available first create di folder inside var folder.

Run command,

php bin/magento setup:di:compile
  • what is the purpose & use of this di directory in magento? Commented Jun 30, 2016 at 8:36
  • when in developer mode, is it normal I got a 'generated' folder in the root after running that command?
    – apedic
    Commented Sep 10, 2017 at 9:04

di folder is generated by magento itself. Each time you run:

bin/magento setup:di:compile

Magento will generate the files

  • Yes but when I try to execute this command, I am getting error Commented Jun 30, 2016 at 7:25
  • 1
    What is that error? Commented Jun 30, 2016 at 7:26
  • 1. var/generation folder is not empty 2.class Cli not found. Commented Jun 30, 2016 at 7:26
  • If i try to delete generation folder ,it automatically regenerates instantly. Commented Jun 30, 2016 at 7:27
  • you might need to clear the cache using: sudo rm -rf var/cache/* var/generation/* and give the ownership to Magento file system owner. Commented Jun 30, 2016 at 7:39

Magento itself creates the directory, var/di.

Missing of this directory (may be due to permission issue) causes

please re-run compile command

message during running of

setup:upgrade command.

I also faced same issue. Then I manually created 'di' directory inside 'var' directory and set proper permission. It solved this issue for me. Then after I didn't get any such message.

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.