Magento 2 Error – Fix php bin/magento setup:di:compile

errormagento2upgrade

After firing this command in command line php bin/magento setup:di:compile I am getting this error:

Cannot declare interface Magento\Framework\App\DeploymentConfig\Writer\FormatterInterface, because the name is already in use in /var/www/html/vendor/magento/framework/App/DeploymentConfig/Writer/FormatterInterface.php on line 9

Can you have a best solution for me?

Thanks

Best Answer

Please try to remove all the directories inside var/generation folder and then run following command :

php bin/magento cache:flush

After that run your command you will be succeed.