3

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...

  • Just to clarify... that entry in registration.php shown as containing a bold DIR is in fact DIR enclosed by double underscores. – Martin Smith Apr 28 '16 at 8:36
  • it would be better if you could post you module.xml aswell.. – Mohammad Mujassam Apr 28 '16 at 9:05
  • module.xml: <?xml version="1.0"?> <config xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Magemood_Shareorder" setup_version="1.0.0"> </module> </config> – Martin Smith Apr 29 '16 at 11:40
  • plz update your post with module.xml file – Rakesh Jesadiya Apr 29 '16 at 11:50
  • Please reset your file permissions and try again, the fact it says There are no commands defined in the "module" namespace. is not okay and probably file permission related – Frank Groot Apr 16 '18 at 14:59
2

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.

0

Create module.xml in etc folder as follows :

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Namespace_Modulename" setup_version="1.0.0">
    </module>
</config>

Also verify that your module is under app/code directory.

  • Hi Deep, Thanks for the feedback. However, I should have clarified that I do already have a module.xml in the format you specify in the location .../app/code/_vendorname_/_modulename_/etc So, it's nothing so straightforward I'm afraid. – Martin Smith Apr 29 '16 at 11:39
0

Yes, create module.xml file and clear var/generation too. rm -rf var/cache/* var/generation/* You can additionally do rm -rf var/view_processed/* and var/page_cache/*

Console commands do not work anymore because var/generation is not regenerated correctly.

Have permissions set right on var/ dir (On pub/ dir too, mostly on pub/static).

Or you could use console commands 'php bin/magento setup:di:compile' or 'php bin/magento setup:di:compile-multi-tenant'. Do a php bin/magento list to see description or php bin/magento setup:di:compile --help

I assumed you're already on developer mode: php bin/magento deploy:mode:show and you could: php bin/magento deploy:mode:set developer.

But if you're in production mode, clear the 4 directories above and run 1 of the 2 compile commands.

  • Hi, Thanks for the suggestions. Checked/done all the above and I still have the same issue. I'm starting to wonder if there is something wrong with my Composer install. Is it perhaps checking for files in the wrong locations? – Martin Smith May 3 '16 at 7:54
  • I don't see how composer would look into other place than vendors and app/code. When you run a command with other user that doesn't have permissions in var it may say it can't see stuff. – obscure May 3 '16 at 10:41
0

as you posted your module.xml we can see xmlns:xsi="w3.org/2001/XMLSchema-instance"; having problem.

My be its by mistake or something one colon(;) is also there remove that..

So now you full module.xml is as below

<?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="Magemood_Shareorder" setup_version="1.0.0">
    </module>
</config>

in yours http://www. was missing & extra colon(;) need to be removed.

Also set the file permission as per Magento official document

Hope this will solve the problem.

  • Hi - the remainder of the URL was removed by the mini-Markdown formatting of the post. The actual URL in the module.xml file is correct. I'm also not clear how the semi-colon turned-up in the post There is no semi-colon in my xml file. I'll try amending the xsi:noNamespaceSchemaLocation parameter in line with your last post and see if that works. I'll also double-check the permissions. Thanks – Martin Smith Apr 29 '16 at 12:59
0

I know the post is old, but if anyone else has this error using CLI :

[Zend_Json_Exception]
Decoding failed: Syntax error

As MagentoMan said, it means it probably comes from an error in your composer.json file.

The first thing you should do is to check for JSON errors in it. To do so, online JSON validators work great : just copy/paste the content of your file, click on validate and they tell you what's wrong in your file.

In your case, you have a issue with your double quote at the second line :

    "name": “magemood/shareorder"

You can see that you have a special double quote () instead of a regular one (") before magemood.

Same thing further in the code :

    "psr-4": {“Magemood\\Shareorder\\": "" },

Fix this two errors and your composer.json should work well.

0

For whatever it's worth, my issue was actually due to the contents of the module.xml file. The was using setup_version="1.0.0" and simply needed updated to setup_version="2.0.0"

Even if you're following the "Creating a Magento admin page" tutorial direct from Magento it will thrown an error if you're sporting Magento 2.2.0 and cli-enable or run setup:upgrade

-1

Try below code in module.xml file

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Namespace_Modulename" setup_version="1.0.0">
</module>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.