Magento2 is full of surprises and I am loving and hating it at the same time. I fix one issue and another issue comes up sooner or later.

Mostly, I have been using Ubuntu for Magento 2 development but I decided to try it on Windows to test the platform performance. Installation was nice and easy and I was able to install demo data without any issue.

After setting up the initial version, I decided to create my own extension which involved a few frontend templating. Everything was normal until I ran ‘php bin\magento setup:di:compile’. Screenshot below.

Magento CLI fatal error

I was served with a fatal error and after scratching my head a few times – and of course hitting on the wall a few times, I decided to remove var/generation directory. It all went fine this time. Alright, so to cut the long store short, do the following:

STEPS:

  1. Don’t panic
  2. Take a deep breath
  3. Remove {magento_directory}/var/generation/
  4. Run ‘php bin/magento setup:di:compile’ again

Did it fix your issue? Leave a comment below to let others know :)