Magento – Magento 2 module not registering and causing CLI to fail

clicomponentcomposerextensionsmagento2

I am in the early stages of test developing a Magento 2 extension – and I am having problems with registration of the module. The confusing thing is (I think) I am following the same method that previously resulted in successful registration of the module! Also, the presence of my registration.php file is causing the Magento CLI to fail.
I am hoping somebody can spot an obvious error/issue in what I am doing – or, failing that, give me some pointers on how to troubleshoot the issue.

I am working in Magento 2.04 CE
The OS is CentOS
SELinux is set to permissive

I have placed the composer.json and registration.php files in the root directory of my module. They reside in directory app/code/vendorname/modulename. I also have a module.xml file in the app/code/vendorname/modulename/etc directory.

Content of the composer.json:

{
  "name": “magemood/shareorder",
  "description": "A Magento 2 module that shares orders with other applications",
  "type": "magento2-module",
  "version": "1.0.0",
  "license": [
    "OSL-3.0",
    "AFL-3.0"
  ],
  "require": {
    "php": "~5.5.0|~5.6.0|~7.0.0",
    "magento/framework": "~100.0.4"
  },
  "autoload": {
    "psr-4": {“Magemood\\Shareorder\\": "" },
    "files":["registration.php"]
  }
}

The content of registration.php:

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'Magemood_Shareorder',
    __DIR__
);

As well as not resulting in successful registration of the module, the presence of these files causes the Magento CLI to fall over.

[Zend\ServiceManager\Exception\ServiceNotCreatedException]
An abstract factory could not create an instance of
magentosetupconsolecommandmoduleuninstallcommand(alias:
Magento\Setup\Console\Command\ModuleUninstallCommand).

[Zend\ServiceManager\Exception\ServiceNotCreatedException]
An exception was raised while creating
"Magento\Setup\Console\Command\ModuleUninstallCommand"; no instance
returned

[Zend_Json_Exception]
Decoding failed: Syntax error

Also, if I try running something like: php bin/magento module:status

I get:

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

I also have the output from running these commands in verbose mode. However, I have excluded these to keep this post to a reasonable length. I can post these separately.

Any help much appreciated…

I have added some sample exception trace ..

Exception trace:
() at vendor/zendframework/zend-servicemanager/src/ServiceManager.php:1135
Zend\ServiceManager\ServiceManager->createFromAbstractFactory() at vendor/zendframework/zend-servicemanager/src/ServiceManager.php:646
Zend\ServiceManager\ServiceManager->doCreate() at vendor/zendframework/zend-servicemanager/src/ServiceManager.php:598
Zend\ServiceManager\ServiceManager->create() at setup/src/Magento/Setup/Console/CommandList.php:89
Magento\Setup\Console\CommandList->getCommands() at vendor/magento/framework/Console/Cli.php:107
Magento\Framework\Console\Cli->getApplicationCommands() at vendor/magento/framework/Console/Cli.php:84
Magento\Framework\Console\Cli->getDefaultCommands() at vendor/symfony/console/Symfony/Component/Console/Application.php:91
Symfony\Component\Console\Application->__construct() at vendor/magento/framework/Console/Cli.php:76
Magento\Framework\Console\Cli->__construct() at bin/magento:24

Update:
Still no luck on this issue. I am starting to wonder if there is a problem with my Composer install. Could it be Composer is looking for files in the wrong locations? I'm going to check my Composer install and review Composer documentation. Any pointers/help on this much appreciated.

Another update on the issue. I have still been unable to resolve. However, I have been able to workaround by by-passing Composer. This is OK for getting the module working for test purposes. So, it looks as though the registration.php and module.xml files were fine – and the issue lies with either my composer.json file… or the way I have Composer setup on my system…

Best Answer

If you get the error "Decoding failed: Syntax error" I would check the module's composer.json file. For me this has happened a couple of times due to a comma that is not needed inside the require parameters.

If your composer file has this:

"require": {
    "php": "~5.6.0|7.0.2|~7.0.6",
    "magento/module-catalog": "101.0.*",
    "magento/module-checkout": "100.1.*",
},

You will see this error every time. Instead, remove the comma on your last required value. It should now look like this.

"require": {
    "php": "~5.6.0|7.0.2|~7.0.6",
    "magento/module-catalog": "101.0.*",
    "magento/module-checkout": "100.1.*"
},

I haven't tested but this error would probably happen for each parameter if the last value has a comma at the end.

Related Topic