I created a module.xml under the app/code/my/module/etc folder.
<?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="my_module" setup_version="1.0.0" />
</config>
Than I tried to enable the module with following command
php -f bin/magento module:enable --clear-static-content my_module
And get this error:
Unknown module(s): 'my_module'
Why don't Magento find the module?
Here is the error after executing the flush command:
[InvalidArgumentException]
There are no commands defined in the "cache" namespace.
Now here is the error:
Additionally to the xml syntax in the module.xml I added comments. These comments caused the error.
Best Answer
Well you have to first clear the cache by running the following command.
or
Then as you executed cache commands, it is possible that permissions are revoked on many files which are being executed during module enabling and disabling.
So if you're on linux(Ubuntu/Debian) then provide full permissions to your root magento directory as below:
Then, provided you've already created 'registration.php' file in your module directory(magento2root/app/code/My/Module/) like below,
run the module enable command you mentioned in your question.
It is not mandatory to have 'composer.json' for module enable-disable, composer.json is needed for git-based tasks(commit module code/update module code etc.) if you have active repo of your site at Github.