I have been trying to create a simple composer package. But I'm stuck with the following issue. Dont know how to resolve this.
[InvalidArgumentException]
Could not find package sarav/sample-package at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability
Package Url : https://packagist.org/packages/sarav/sample-package
I ran the following composer command
composer require sarav/sample-package
My composer contents
{
"name": "sarav/sample-package",
"description": "Sample package",
"type": "Library",
"license": "MIT",
"authors": [
{
"name": "Sarav",
"email": "me#sarav.co"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"Sarav": "src/"
}
}
}
Your package config looks good to me, but your Git repo doesn't have any tagged versions.
Use git tag v1.0.0 or whatever version is appropriate, then git push origin --tags to update on GitHub.
Alternatively, you can go without tagged versions by specifying the master branch when you require the package, like so:
composer require sarav/sample-package dev-master
You can require any branch in this manner, but the dev- prefix is mandatory.
Related
I am learning on how to upload a package on packagist.org. I created a github repository for testing with composer.json file -
https://github.com/perials/check
and a composer package using this github repository - https://packagist.org/packages/perials/check
When I try to install this package using composer require perials/check I get below error
[InvalidArgumentException]
Could not find a version of package perials/check matching your minimum-stability (stable). Require it with an explicit version constraint allowing its desired stability.
From what I read in other related questions on SO this error occurs if there are no stable releases of github branch. But thing is that I already have some releases.
I also tried composer require perials/check:dev-master and composer require perials/check:7.1.0 but then I get below error
[InvalidArgumentException]
Could not find package perials/check.
Did you mean this?
perials/check
It was an issue with Singapore mirror for the packagist metadata. Now it should be resolved. https://github.com/composer/composer/issues/8347#issuecomment-537176755
If still not solve your issue please add "minimum-stability": "dev" in your composer.json
{
"name": "perials/check",
"description": "Package for testing packagist",
"license": "MIT",
"authors": [
{
"name": "Perials",
"email": "info#perials.com"
}
],
"autoload": {
"psr-4": {"Abc\\": "src/xyz"}
},
"require": {},
"minimum-stability": "dev"
}
I am also learning how to create packages and have the same problem, but in my case I created a v1.0.0 tag for my package and that solves the problem.
You can accept no stable version packages. See composer in docs (https://getcomposer.org/doc/04-schema.md#package-links).
Paste piece here for convinience:
You can apply them to a constraint, or apply them to an empty constraint if you want to allow unstable packages of a dependency for example.
composer.json:
{
"require": {
"monolog/monolog": "1.0.*#beta",
"acme/foo": "#dev"
}
}
In your case you would do:
{
"require": {
"perials/check": "7.1.0#dev"
}
}
and then run rm composer.lock; composer install.
I have created a simple PHP-validation plugin.
I submit it in Packagist.Everything in Packagist seems fine but when I run my composer require command
composer require rahulreghunath11/php-rvalidation
Could not find package rahulreghunath11/php-rvalidation at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability
showing this error.
my composer file is
{
"name": "rahulreghunath11/php-rvalidation",
"type": "library",
"description": "PHP form validation plugin ",
"keywords": ["validation","bootstrap validation"],
"homepage": "https://github.com/rahulreghunath11/php-form-validation",
"license": "MIT",
"authors": [
{
"name": "Rahul Reghunath",
"email": "reghunath11#gmail.com",
"role": "developer"
}
]
}
any idea?
That error means that the composer.json file for your project (NOT your validation plugin) is missing a minimum-stability indicator that allows development packages, so it's defaulting to stable.
Your validation plugin is only available as dev-master, because you haven't tagged any releases in Github yet. That means that in order for the require to work, you either have to explicitly tell it to fetch dev-master, or you need to set minimum-stability for your project to dev.
Edit:
To tell your project to use the dev-master package, specify it manually in your (project) composer.json file:
{
"name": "example/example-app",
"require": {
"rahulreghunath11/php-rvalidation": "dev-master"
}
}
Alternatively, if you want to be able to use composer require from the commandline and have it add the dev-master version automatically, set the minimum-stability to dev in your (project) composer.json file:
{
"name": "example/example-app",
"minimum-stability": "dev",
"require": {
}
}
Now composer will let you add packages that do not have releases:
composer require rahulreghunath11/php-rvalidation
I am in the process in developing my first package. The package is working.
Now I want to use Laravels Collective's HTML in my package (dependencies).
Therefor I added this to the package's composer file:
(this composer.json is in the root of the package: /packages/vendor/package)
{
"name": "vendor/package",
"description": "",
"license": "MIT",
"authors": [
{
"name": "firstname lastname",
"email": "info#domain.nl"
}
],
"minimum-stability": "stable",
"require": {
"twbs/bootstrap": "dev-master",
"laravelcollective/html": "5.3.*"
}
}
I've included the package in Laravel's own composer.json:
...
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Vendor\\Package\\": "packages/vendor/package/src"
}
},
...
When I do composer update the dependencies of the package are not updated. What am I missing here?
You have to define a local composer repository if your package is not uploaded to packagist.org yet. Inside Laravels' application composer.json add a local repository like this:
"repositories": [
{
"type": "path",
"url": "/full/or/relative/path/to/development/my-package"
}
],
"require": {
"my-package": "*"
}
You have to define the package src directory inside the package composer.json and not inside the Laravels' own composer.json. Try and define it like this inside packages' composer.json:
"require" : {
"twbs/bootstrap": "dev-master",
"laravelcollective/html": "5.3.*"
},
"autoload" : {
"psr-4" : {
"PackageNamespace\\PackageClass\\" : "src/"
}
},
UPDATE
In order to do a proper package development, you have to keep your package files at some directory other than /vendor/ composer directory. The main reason is that the developer can delete the entire /vendor directory if there might be conflict problems or for cleaning up and setting up everything under composer /vendor path. I use a very simple method and I keep my own packages at:
<application>/dev/packages/<package-namespace>/<package-name>
You have to initialize a git at your package for composer to recognize the repository. To make a git package, go at your package location and run the following commands:
cd <application>/dev/packages/<package-namespace>/<package-name>
git init
git add *
git commit -m "Initial commit"
You may also have to set the git config user.name and git config user.email before commit, for the git to be able to recognize someone and allow the local commits:
git config user.email "you#example.com"
git config user.name "Your Name"
In my example, the namespace is lytr and the package name is testpkg.
The <application>/dev/packages/<package-namespace>/<package-name>/composer.json (<application>/dev/packages/lytr/testpkg) will look like this:
{
"name" : "lytr/testpkg",
"description" : "Test package of Lytr",
"keywords" : [
"test",
"package"
],
"license" : "MIT",
"require" : {
"twbs/bootstrap" : "dev-master",
"laravelcollective/html" : "5.3.*"
},
"autoload" : {
"psr-0" : {
"Lytr\\TestPkg\\" : "src"
}
},
"extra" : {
"branch-alias" : {
"dev-master" : "1.0-dev"
}
},
"minimum-stability" : "dev"
}
Then at your application <application>/composer.json you'll have a local git repository and your package like this:
"repositories": [
{
"type": "path",
"url": "<full-application-path>/dev/packages/lytr/testpkg"
}
],
"require" : {
"lytr/testpkg": "*"
},
"minimum-stability": "dev",
I include "minimum-stability": "dev", because we are using master-dev versions. Then after running the composer update command only having the "twbs/bootstrap" : "dev-master", at the package requirements, we'll see the following output on the console window:
And after we change the package composer.json and require the "laravelcollective/html" : "5.3.*",, we do a composer update and we see composer installs the laravelcollective/html package properly:
I know this might look confusing and somehow overkill, but this is a proper way for developing packages for composer. You can also have your packages at a git repository and make composer clone that repository instead of your local files. When you're done developing the package and you release it under https://packagist.org/, then you will just have to require your package as any other normal package without the repositories and all the local git thing. Remember, you are at development phase of your package and not at production.
I am using Laravel 5.2.23 and am unable to pull in my new package, bsapaka/metattribute. I get the exception:
[InvalidArgumentException]
Could not find package bsapaka/metattribute at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability
Composer seems to have it:
Running composer show bsapaka/metattribute returns:
name : bsapaka/metattribute
descrip. : classes for Laravel attributes
keywords : attribute, attributes, properties, alias, meta attribute
versions : dev-master
type : library
(more)
So I am wondering if I am missing something in the composer.json:
{
"name": "bsapaka/metattribute",
"type": "library",
"description": "classes for Laravel attributes",
"keywords": [
"attribute",
"attributes",
"properties",
"meta attribute",
"alias"
],
"homepage": "https://github.com/bsapaka/metattribute",
"license": "MIT",
"require": {
"illuminate/support": "~5.1",
"php" : "~5.5|~7.0"
},
"require-dev": {
"phpspec/phpspec": "~2.2"
},
"autoload": {
"psr-4": {
"bsapaka\\metattribute\\": "src/"
}
},
"minimum-stability": "stable"
}
I have done a good bit of docs reading, troubleshooting, adding in mininum-stability, checking the versioning, comparing against other packages, validating JSON, looking for the tidbits I missed etc, and at this point I could really use some guidance on where I might be going wrong. Thanks for reading, and I appreciate your help.
You don't have any version tag defined in your master branch on GitHub.
If there is no version tag then Composer doesn't know which version is the stable one. So if you have "minimum-stability": "stable" in the project which is requiring your self made package it can't find any stable version.
Create a new tag (e.g. 1.0.0) in your master branch on GitHub to declare the latest commit as stable or use the dev-master version and "minimum-stability": "dev" in the project which is requiring your self made package.
I have written a library that I want to use in another project. However, when I add the library dependency to my project I get the following error after running composer update -vvv:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for my/library dev-master -> satisfiable by my/library[dev-master].
- my/library dev-master requires doctrine/migrations dev-master -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
This error is very confusing to me since my project has my library as it's only dependency, i.e. my project composer.json looks like this:
{
"name": "my/project",
"type": "project",
"description": "My project",
"autoload": {
"psr-0": { "MyNamespace\\": ["src/", "tests/src/"] }
},
"repositories": [ {
"type": "vcs",
"url": "git#bitbucket.org:my/library"
} ],
"require": {
"php": ">=5.5",
"my/library": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "3.*"
}
}
As you can see, pretty straight forward. The reason the version of my library is requiring dev-master is because master is currently the only branch I work on (I work alone, no need for other branches at the moment).
So far the only way for the resolve this problem is by adding the dependencies of my library composer.json to my project's composer.json which seems like an unnecessary step.
How can I resolve this dependency issue?
It looks to me as if it is a stability issue. Add the following two lines to your composer.json:-
"minimum-stability": "dev",
"prefer-stable": true,
ref:- minimum-stability & prefer-stable
Hopefully that will sort out your problem.