【Laravel8】”composer require google/apiclient”実行時にエラーになる場合の対処方法

2021年8月26日Laravel

スポンサーリンク

Google Cloud API(今回はCloud Vision API)をLaravelで使いたいと思って、
“composer require google/apiclient"を実行したら以下のエラーになった。
※"composer require google/cloud-vision"や"composer require google/cloud-language"でも同様のエラーは出る。

root@b23f92940510:/work/src# composer require google/apiclient
Using version ^2.10 for google/apiclient
./composer.json has been updated
Running composer update google/apiclient
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - google/apiclient[dev-master, v2.10.0, ..., v2.10.1] require guzzlehttp/psr7 ^1.2 -> found guzzlehttp/psr7[1.2.0, ..., 1.x-dev] but the package is fixed to 2.0.0 (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.
    - google/apiclient 2.x-dev is an alias of google/apiclient dev-master and thus requires it to be installed too.
    - Root composer.json requires google/apiclient ^2.10 -> satisfiable by google/apiclient[v2.10.0, v2.10.1, 2.x-dev (alias of dev-master)].

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.

“guzzlehttp/psr7″のバージョンが2.0.0で固定されているのがだめらしい。

どうやら、composer.jsonの以下の"guzzlehttp/guzzle"の依存関係として"guzzlehttp/psr7″がインストールされてバージョンが固定されているらしい。

"guzzlehttp/guzzle": "^7.0.1",

解決方法

その1

以下のように"guzzlehttp/guzzle"を削除したあとに"composer require google/apiclient"を実行したら成功した。

composer remove guzzlehttp/guzzle
composer require google/apiclient

<補足>

“composer require google/apiclient"をインストールした際に"guzzlehttp/guzzle"も依存関係としてインストールされているので"guzzlehttp/guzzle"はcomposer.jsonから削除しても特に問題なさそう。
package-lock.jsonで"google/apiclient"のインストール前後での"guzzlehttp/psr7″のバージョンを比較すると、

前:"2.0.0″
後:"1.8.2″

となっていたので、"guzzlehttp/psr7″のバージョンが高く、"google/apiclient"のサポート外だったので、インストール時に最初に記載したエラーが出ていたよう。

その2

※上記の補足で説明しているように直接の原因は"guzzlehttp/psr7″のバージョンが"google/apiclient"のサポート外であることなので、"guzzlehttp/psr7″のバージョンをcomposer.jsonで指定してあげても良い。

手順としてはcomposer.jsonの

"guzzlehttp/guzzle": "^7.0.1",

の下に

"guzzlehttp/psr7": "1.8.2",

を記述して、

composer update
composer require google/apiclient

とやる。

Laravel

Posted by ton