bobo
bobo

Reputation: 8727

Failed to require a package using Composer

I would like to require this package in my project: lucianocosta/jquery.mtz.monthpicker

So I added it in my composer.json file:

{
      "name": "yiisoft/yii2-app-advanced",
      "description": "Yii 2 Advanced Application Template",
      "keywords": ["yii2", "framework", "advanced", "application template"],
      "homepage": "http://www.yiiframework.com/",
      "type": "project",
      "license": "BSD-3-Clause",
      "support": {
                "issues": "https://github.com/yiisoft/yii2/issues?state=open",
                "forum": "http://www.yiiframework.com/forum/",
                "wiki": "http://www.yiiframework.com/wiki/",
                "irc": "irc://irc.freenode.net/yii",
                "source": "https://github.com/yiisoft/yii2"
      },
      "minimum-stability": "stable",
      "require": {
                "php": ">=5.4.0",
                "yiisoft/yii2": "*",
                "yiisoft/yii2-bootstrap": "*",
                "yiisoft/yii2-swiftmailer": "*",
                "yiisoft/yii2-gii": "*",
                "yiisoft/yii2-faker": "*",
                "google/apiclient": "1.0.*@beta",
                "asimlqt/php-google-spreadsheet-client": "2.2.*",
                "phpoffice/phpexcel": "*",
                "lucianocosta/jquery.mtz.monthpicker": "dev-master"
      },
      "require-dev": {
                "yiisoft/yii2-codeception": "*",
                "yiisoft/yii2-debug": "*"
      },
      "config": {
                "process-timeout": 1800
      },
      "extra": {
                "asset-installer-paths": {
                          "npm-asset-library": "vendor/npm",
                          "bower-asset-library": "vendor/bower"
                }
      }

}

Then I run the composer update command but I got this message:

Your requirements could not be resolved to an installable set of packages.

Problem 1 - The requested package lucianocosta/jquery.mtz.monthpicker could not be found in any version, there may be a typo in the package name.

Potential causes:

Without altering any minimum-stability setting, is this possible that I can require this package successfully?

Upvotes: 0

Views: 1953

Answers (2)

freezy
freezy

Reputation: 36

Package which you require is not Composer package because Composer is PHP package manager and package which you want to use is just for frontend.

Frontend packages are mantained with Bower but Yii suggests you to install composer-assets-plugin which can handle Bower packages through composer.json and then you don't need to maintain them in separate bower.json.

Then you need to find correct Bower package name. You can do it through website http://bower.io/search/?q=monthpicker or if you have Bower installed you can search for this package from command line like this:

bower search jquery.mtz.monthpicker

Search results:
    monthpicker git://github.com/lucianocosta/jquery.mtz.monthpicker.git

When you have your package name (in this case monthpicker), you just need to add it in require section of your composer.json prefixed with bower-asset/ (in this case bower-asset/monthpicker.

Here is a fixed version of your require section:

"require": {
    "php": ">=5.4.0",
    "yiisoft/yii2": "*",
    "yiisoft/yii2-bootstrap": "*",
    "yiisoft/yii2-swiftmailer": "*",
    "yiisoft/yii2-gii": "*",
    "yiisoft/yii2-faker": "*",
    "google/apiclient": "1.0.*@beta",
    "asimlqt/php-google-spreadsheet-client": "2.2.*",
    "phpoffice/phpexcel": "*",
    "bower-asset/monthpicker": "dev-master"
},

Upvotes: 2

Pᴇʜ
Pᴇʜ

Reputation: 57743

The problem is that the requested package is not a composer package (it has no composer.json) and it is not available via the packagist.org repository. That means that the author of this package didn't provide support for composer.

A repository is a package source. It's a list of packages/versions. Composer will look in all your repositories to find the packages your project requires.

By default only the Packagist repository is registered in Composer. You can add more repositories to your project by declaring them in composer.json.

But it is possible to register new repositories in your composer.json. The following code registers a repository for lucianocosta/jquery.mtz.monthpicker and makes use of the RobLoach/component-installer to bring them out of the /vendor folder. If you don't need this just remove the extra and the require section within the package section.

"repositories": [
     {
        "type": "package",
        "package": {
            "name": "lucianocosta/jquery.mtz.monthpicker",
            "version": "1.0",
            "type": "component",
            "dist": {
                "url": "https://github.com/lucianocosta/jquery.mtz.monthpicker/archive/master.zip",
                "type": "zip"
            },
            "extra": {
                "component": {
                    "scripts": [
                        "jquery.mtz.monthpicker.js"
                    ]
                }
            },
            "require": {
                "robloach/component-installer": "*"
            }
        }
    }
],
"require": {
    "lucianocosta/jquery.mtz.monthpicker": "1.*"
},

Upvotes: 1

Related Questions