June 28th, 2019
In trying to set up a Magento 2 instance, I came across an issue trying to set developer mode through CLI where upon entering the command it would fail with the following message:
There are no commands defined in the "deploy:mode" namespace.
This issue sometimes fails with other messages like:
There are no commands defined in the "setup" namespace.
I tried several different methods of calling bin/magento, such as:
bin/magento deploy:mode:set developer
php bin/magento deploy:mode:set developer
sudo bin/magento deploy:mode:set developer
sudo php bin/magento deploy:mode:set developer
But none of them would yield any different result.
After searching for a bit I came across a GitHub issue that had just the commands I needed.
To fix this issue just run these three commands in your CLI:
rm -Rf var/di/* sudo php bin/magento setup:upgrade sudo php bin/magento setup:di:compile
After that, you should be able to run the command and get the expected result!
This also works if you are getting an error like “Interceptor does not exist”, just run the commands above and clear the cache.
If this set of commands does not work, you may have a corrupt install or incorrect configuration.
If that is the case, check the file app/etc/env.php for issues.