とあるプロジェクトでLaravelのバージョンアップを行いましたところ、下記のようにLaravel Excelをインストールしようとしたところエラーが発生しました。
composer require maatwebsite/excel
以下がエラー文です。
Symfony\Component\ErrorHandler\Error\FatalError Declaration of Maatwebsite\Excel\Cache\MemoryCache::get($key, $default = null) must be compatible with Psr\SimpleCache\CacheInterface::get(string $key, mixed $default = null): mixed at vendor/maatwebsite/excel/src/Cache/MemoryCache.php:62 58▕ 59▕ /** 60▕ * {@inheritdoc} 61▕ */ ➜ 62▕ public function get($key, $default = null) 63▕ { 64▕ if ($this->has($key)) { 65▕ return $this->cache[$key]; 66▕ } Whoops\Exception\ErrorException Declaration of Maatwebsite\Excel\Cache\MemoryCache::get($key, $default = null) must be compatible with Psr\SimpleCache\CacheInterface::get(string $key, mixed $default = null): mixed at vendor/maatwebsite/excel/src/Cache/MemoryCache.php:62 58▕ 59▕ /** 60▕ * {@inheritdoc} 61▕ */ ➜ 62▕ public function get($key, $default = null) 63▕ { 64▕ if ($this->has($key)) { 65▕ return $this->cache[$key]; 66▕ } +1 vendor frames 2 [internal]:0 Whoops\Run::handleShutdown() Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
どうも依存ライブラリである「simple-cache」の新しい物と互換性がとれない模様。
こちらのページを参考にして、下記のようにバージョン指定してインストールしたらエラーも解消されました。
composer require psr/simple-cache:^2.0 composer require maatwebsite/excel