I am getting the following error while adding a new module to my Magento 2 installation and running the command on terminal php bin/magento setup:upgrade
.
[InvalidArgumentException] There are no commands defined in the “setup” namespace
The same kind of error will be displayed in terminal when I try to run other commands like php bin/magento module:status
[InvalidArgumentException] There are no commands defined in the “module” namespace
php bin/magento cache:clean
[InvalidArgumentException] There are no commands defined in the “cache” namespace
Solution 1:
The general main cause of this kind of error is missing etc/module.xml
file in your module. Or, missing setup_version
code in module.xml
file.
Here is a sample module.xml file of a module named YourNamespace_YourModule.
app/code/YourNamespace/YourModule/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="YourNamespace_YourModule" setup_version="2.0.0" />
</config>
If you are not sure which module is creating this problem, you can try removing each module and check to find the problematic module.
Solution 2:
If solution 1 doesn’t help then you can try this second solution.
Give full control (read/write/execute) to var and pub directory solved this issue for me.
sudo chmod -R 777 var pub
You may also try running the following command:
sudo php -f bin/magento module:enable --clear-static-content YourNamespace_YourModule
Hope this helps.
Thanks.