2

In my module, I have created a composer.json file with this code and pushed it to git

{
    "name": "lovat/magento2-api",
    "description": "Lovat Api Sales Module for Magento 2",
    "type": "magento2-module",
    "version": "1.0.0",
    "require": {
        "php": "^7.2.2",
        "magento/framework": "101.0.*"
    },
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "Lovat\\Api\\": ""
        }
    }
}

enter image description here After I use this command: composer require lovat/magento2-api but I have this error

[InvalidArgumentException]                  
  Could not find package lovat/magento2-api.  
                                              
  Did you mean one of these?                  
      bower-asset/u2f-api                     
      bower-asset/api                         
      bower-asset/gomc-api                    
      bower-asset/mu.api                      
      bower-asset/goog-api 
3
  1. Create a Github repository named (magento2-api) your lovat account(github.com/lovat/). Ignore if you already have it.

     {
     "name": "lovat/magento2-api",
     "description": "Lovat Api Sales Module for Magento 2",
     "type": "magento2-module",
     "version": "1.0.0",
     "require": {
         "php": "^7.2.2",
         "magento/framework": "101.0.*"
     },
     "autoload": {
         "files": [
             "registration.php"
         ],
         "psr-4": {
             "Lovat\\Api\\": ""
         }
     }
    

    }

  2. push the code to the github.com/lovat/magento2-api

     git add . ; git commit -m 'initial commit' ; git push origin master
    
  3. tag it the same version mention in the composer.json here (1.0.0)

     git tag 1.0.0 ; git push origin --tags
    
  4. Open https://packagist.org/packages/submit using your account and submit the github repo URL.

If you already have then just hit the Update button or reload page. You should see the change.

E.g. https://packagist.org/packages/lovat/magento2-api

  1. ask anyone to run composer require lovat/magento2-api

NOTE: Make sure to keep the same version number("version": "1.0.0",) mention in the composer.json and git tag x.x.x. Once you push the tags then packagist will pickup automatically.

Try to change the version in composer.json if its not working.

2

Here is the sample step for installing your module through composer:

  1. Create a git repository for your module
  2. Now create a package for your module. Here is the link where you submit your new package:https://packagist.org/packages/submit.

Here is the link for detail

You can check this git repository as an example

1
  • thanks for help! can you tell me why it doesn't work composer require lovat/module-lovat but composer require lovat/module-lovat:dev-master working Aug 7 '20 at 13:23

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.