Composer: How to install dependencies recursively automatically? - composer-php

In using composer require to install packages / using composer install with composer.json, I run into the following problem:
"A" requires "B". After adding "B" and composer install
again:
"B" requires "C". After adding "C" and composer install
again:
"C" requires "D". After adding "D" and composer install
again:
I am pretty sure I am missing something, or it would be the worst ever design when the dependency chain is long.
How do I make the composer automatically install all missing dependencies for installing "A" recursively, instead of loading for like 2-3 minutes each round only to tell me something is missing again, or there are better ways to install dependencies?
Update:
Runs into the following error when using "update":
Installation request for illuminate/session 5.6.* -> satisfiable by illuminate/session[v5.6.0, v5.6.1, v5.6.10, v5.6.11, v5.6.12, v5.6.2, v5.6.3, v5.6.4, v5.6.5, v5.6.6, v5.6.7, v5.6.8, v5.6.9].
How do I install illuminate/session 5.6.* before I install illuminate/session 5.6.* so that I can be able to install illuminate/session 5.6.*? Am I missing a time machine?

If you want to update a package that also updates a dependency you have installed, you should probably pass the argument --with-dependencies
For example composer update vendor/package --with-dependencies

Related

Why haven't install predis on laravel 8

According laravel manual https://laravel.com/docs/8.x/redis for install predis, need run: composer require predis/predis. When that command is running (for laravel 8) - appear next Error:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- facade/ignition is locked to version 2.4.2 and an update of this package was not requested.
- facade/ignition 2.4.2 requires php ^7.2.5 -> your php version (8.0.0) does not satisfy that requirement.
Problem 2
- facade/ignition-contracts 1.0.1 requires php ^7.1 -> your php version (8.0.0) does not satisfy that requirement.
- nunomaduro/collision v4.3.0 requires facade/ignition-contracts ^1.0 -> satisfiable by facade/ignition-contracts[1.0.1].
- nunomaduro/collision is locked to version v4.3.0 and an update of this package was not requested.
In my composer.json: "php": "^7.2.5|^8.0",
What here is wrong))?
You need to update facade/ignition and nunomaduro/collision first to support PHP 8 in your project.
Running the following commands should update them accordingly.
composer require --dev facade/ignition nunomaduro/collision
composer require predis/predis
i run comand: composer require --dev facade/ignition nunomaduro/collision and have got new Error: Your requirements could not be resolved to an installable set of packages.
Problem 1
- facade/ignition[2.10.0, ..., 2.10.2] require facade/ignition-contracts ^1.0.2 -> found facade/ignition-contracts[1.0.2] but the package is fixed to 1.0.1 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
- Root composer.json requires facade/ignition ^2.10 -> satisfiable by facade/ignition[2.10.0, 2.10.1, 2.10.2].
Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
I have new laravel 8 project (blog) && use new Vagrant Homestead (with all updates) && i use laravel 8 manual)) may be laravel developers is a little busy and is a little tired to give full instruction in manual). I think may be for Laravel8 Homestead allready is not suitable and need Docker and Sail... But project work (with the exception of predis) Now i use phpredis. May be will try use docker... As for Vagrant&&Homestead - https://laravel.com/docs/8.x/homestead#introduction i don't understand what is problem to use that technology .... god with they)...

Problem of Laravel Framework version for using the package mailjet/laravel-mailjet

I've a problem for using mailjet/laravel-mailjet, it seems a problem of versions.
I was using Laravel Framework 5.6.33 and i got
Can only install one of: laravel/framework[v5.6.39, 5.4.x-dev].
i've change my composer.json and now, i'm using Laravel Framework 5.6.39 but i've still the same problem
$ php artisan --version
Laravel Framework 5.6.39
There is the answer when i try to install mailjet/laravel-mailjet
$ composer require mailjet/laravel-mailjet
Using version ^1.1 for mailjet/laravel-mailjet
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Can only install one of: laravel/framework[v5.6.39, 5.4.x-dev].
- Can only install one of: laravel/framework[5.4.x-dev, v5.6.39].
- Can only install one of: laravel/framework[5.4.x-dev, v5.6.39].
- mailjet/laravel-mailjet 1.1.0 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev].
- Installation request for mailjet/laravel-mailjet ^1.1 -> satisfiable by mailjet/laravel-mailjet[1.1.0].
- Installation request for laravel/framework 5.6.39 -> satisfiable by laravel/framework[v5.6.39].
the 4th line explains it all.
mailjet/laravel-mailjet 1.1.0 requires laravel/framework 5.4.*
so, you can't use v5.6.39, only 5.4.*

Composer Google API Download Failed

I tried to download google api using composer to a legacy code but, the following error appeared:
composer require google/apiclient:^2.0
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for google/apiclient 2.0 -> satisfiable by google/apiclient[v2.0.0].
- google/apiclient v2.0.0 requires google/auth 0.8 -> satisfiable by google/auth[v0.8].
- Conclusion: don't install guzzlehttp/psr7 1.4.2
- google/auth v0.8 requires guzzlehttp/psr7 1.2.* -> satisfiable by guzzlehttp/psr7[1.2.0, 1.2.1, 1.2.2, 1.2.3].
- Can only install one of: guzzlehttp/psr7[1.2.0, 1.4.2].
- Can only install one of: guzzlehttp/psr7[1.2.1, 1.4.2].
- Can only install one of: guzzlehttp/psr7[1.2.2, 1.4.2].
- Can only install one of: guzzlehttp/psr7[1.2.3, 1.4.2].
- Installation request for guzzlehttp/psr7 (locked at 1.4.2) -> satisfiable by guzzlehttp/psr7[1.4.2].
Installation failed, reverting ./composer.json to its original content.
What should I do?
Try removing vendor/google and then run composer install again, this worked for me.
Can only install one of: guzzlehttp/psr7[1.2.3, 1.4.2].
Your dependencies led to confusion of two different major versions of the package, but only one can be installed.
The locked at 1.4.2 message means this package has been already installed as per your composer.lock file, and you're trying to install different version not compatible with your existing criteria.
$ composer show -a google/auth | grep psr7
guzzlehttp/psr7 ~1.2
You can check which existing package depends on the locked version by checking the dependency tree:
composer show -t
In some cases, removing composer.lock may help.
Otherwise, to see why (from where) the package is referenced, run:
composer why guzzlehttp/psr7 -t
See also: How to resolve a "Can only install one of:" conflict?
I finally found a solution for me, it works just removing composer.lock!!

Cannot remove composer root package dependency package

I need to remove the package http-interop/http-middleware and replace it with http-interop/http-server-middleware.
It's not a defined package in my composer.json but from what I can see stems from zendframework/zendframework.
In any case, when I try to run composer remove http-interop/http-middleware it does not remove the package. Then, I get this when trying to run composer require http-interop/http-server-middleware
Problem 1
- Conclusion: don't install http-interop/http-server-middleware 1.1.1
- don't install http-interop/http-server-middleware 1.1.0|remove http-interop/http-middleware 0.2.0
- don't install http-interop/http-server-middleware 1.1.0|don't install http-interop/http-middleware 0.2.0
- don't install http-interop/http-server-middleware 1.1.0|don't install http-interop/http-middleware 0.2.0
- Installation request for http-interop/http-server-middleware ^1.1 -> satisfiable by http-interop/http-server-middleware[1.1.0, 1.1.1].
- Installation request for http-interop/http-middleware (locked at 0.2.0) -> satisfiable by http-interop/http-middleware[0.2.0].
I really do not know what to do at this point.
If that is a package required by another package, you cannot remove it without removing that other package. In your case: you have to get rid of zendframework/zendframework first, but that is surely not what you want.
According to https://packagist.org/packages/http-interop/http-middleware/dependents?page=13, the dependency comes from multiple packages in the zendframework. They directly require ^0.4.1 of that package and http-interop/http-server-middleware contains a replace section. So, probably you get it working by adding http-interop/http-server-middleware first and remove http-interop/http-middleware afterwards?

Why does Composer say "Conclusion: don't install" when (seemingly) no obstacles are present?

The following composer.json:
{
"type": "project",
"minimum-stability": "dev",
"require": {
"jasny/bootstrap": ">=3.1.3",
"2amigos/yii2-file-input-widget": "*"
}
}
leads to the following output of composer update:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- 2amigos/yii2-file-input-widget 0.1.2 requires jasny/bootstrap v3.1.0 -> satisfiable by jasny/bootstrap[v3.1.0] but these conflict with your requirements or minimum-stability.
- 2amigos/yii2-file-input-widget 0.1.1 requires jasny/bootstrap v3.1.0 -> satisfiable by jasny/bootstrap[v3.1.0] but these conflict with your requirements or minimum-stability.
- 2amigos/yii2-file-input-widget 0.1.0 requires jasny/bootstrap v3.1.0 -> satisfiable by jasny/bootstrap[v3.1.0] but these conflict with your requirements or minimum-stability.
- 2amigos/yii2-file-input-widget 1.0.0 requires jasny/bootstrap ~3.1.0 -> satisfiable by jasny/bootstrap[v3.1.3].
- 2amigos/yii2-file-input-widget 1.0.1 requires jasny/bootstrap ~3.1.0 -> satisfiable by jasny/bootstrap[v3.1.3].
- 2amigos/yii2-file-input-widget 1.0.2 requires jasny/bootstrap ~3.1.0 -> satisfiable by jasny/bootstrap[v3.1.3].
- 2amigos/yii2-file-input-widget dev-master requires jasny/bootstrap ~3.1.0 -> satisfiable by jasny/bootstrap[v3.1.3].
- 2amigos/yii2-file-input-widget 1.0.x-dev requires jasny/bootstrap ~3.1.0 -> satisfiable by jasny/bootstrap[v3.1.3].
- Conclusion: don't install jasny/bootstrap v3.1.3
- Installation request for 2amigos/yii2-file-input-widget * -> satisfiable by 2amigos/yii2-file-input-widget[0.1.0, 0.1.1, 0.1.2, 1.0.0, 1.0.1, 1.0.2, dev-master, 1.0.x-dev].
Why?
Ok, I understand, why versions 0.1.0–0.1.2 of 2amigos/yii2-file-input-widget can't be installed — because they require jasny/bootstrap of exact version 3.1.0, which conflicts with >=3.1.3 requirement in composer.json (and therefore composer clarifies: but these conflict with your requirements or minimum-stability).
But, from common-sense view, composer can install version 1.0.0 or later of 2amigos/yii2-file-input-widget (which requires jasny/bootstrap of version ~3.1.0, which is satisfiable by 3.1.3). Neither I see any obstacles for installing 2amigos/yii2-file-input-widget 1.0.0+ together with jasny/bootstrap 3.1.3, nor composer writes any explicit clarification about it. Still it says: Conclusion: don't install jasny/bootstrap v3.1.3 — why?
Workaround 1
It seems it works with "prefer-stable": true.
Workaround 2
I actually found the other workaround some time ago: I replace "2amigos/yii2-file-input-widget": "*" with "2amigos/yii2-file-input-widget": "1.0.2", do composer update and then replace it back and do composer update again — and it works.
The question is why it works in so strange way: why it works with more restrictions, but fails with less restrictions (with no clarification). E.g. if it works with 1.0.2 (or with prefer-stable) works — then why it doesn't with * (or without prefer-stable)?
Change the order and it should work, e.g.
{
"minimum-stability": "dev",
"require": {
"2amigos/yii2-file-input-widget": "*",
"jasny/bootstrap": ">=3.1.3"
}
}
Why? I don't know. Most likely a Composer's bug.
I've tested two configurations with different order on the empty folder using composer install command (Composer v1.6.3), the original order fails, however the order above works. I've reported the issue at GH-7215.
The problem might well be that you are manually editing composer.json and then running
$ composer update
Instead, revert the changes to composer.json and then run:
$ composer require jasny/bootstrap:>=3.1.3
$ composer require "2amigos/yii2-file-input-widget:*"
or in one go:
$ composer require jasny/bootstrap:>=3.1.3 "2amigos/yii2-file-input-widget:*"
Note I recommend to avoid the * wildcard as version constraint because it could pull in any version of that dependency, and potentially break your application by pulling in a version that is not compatible with it.
For reference, see:
http://semver.org

Resources