'There are no commands defined in the "setup" namespace : Magento 2

I have installed latest version of Megento 2, everything is working fine frontend, backend and functionality.

I have one issue with bin/magento setup:upgrade command, when I run this command in terminal I get below exception .

[InvalidArgumentException]
There are no commands defined in the "setup" namespace.

Screenshot :

enter image description here

Is there any thing I missed during installation or I need to install some package to let it working?



Solution 1:[1]

Giving full control (read/write/execute) to var and pub directory should solve this issue.

sudo chmod -R 777 var pub

You may also try running the command using sudo.

sudo php bin/magento setup:upgrade

Solution 2:[2]

I wanted to add an answer because the others doens't cover all the problems that could generate this error :

There are no commands defined in the "setup" namespace.

in general.

This error could be caused by permission as said in others answer but we could have other scenario.

  • The absense of : etc/module.xml
  • An error in /etc/module.xml or in /etc/di.xml or others xml extensions under /etc

If you know other scenario please comment this answer.
Hope this help.

Solution 3:[3]

Just remove all the directory of var and remove pub/static directory , it will work bin/magento setup:upgrade

Solution 4:[4]

I encounterd the same error while running commands related to magento. I was missing double_quotes(") in module.xml file of the custom module. So check module.xml file for any typos and setup_version.

Solution 5:[5]

I want to add one more hint check the 'MAGE_MODE' value in env.php it should be correctly set.

Solution 6:[6]

The reason for this error can be seen in the command output: php -f bin/magento.

This will work for most errors like There are no commands defined in the "..." namespace..


A fairly common cause is an error in the VendorName/ModuleName/etc/config.xml.

Solution 7:[7]

simple RUN php bin/magento this will show you details where it is broken

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mukesh Chapagain
Solution 2 Isky
Solution 3 Tim Diekmann
Solution 4 vilas
Solution 5 Ahmer Saeed
Solution 6 Victor S.
Solution 7 Asad Ullah