69
45

More than 3 years have passed since last update.

composer2.xでLaravelが動かなくなったら

Last updated at Posted at 2020-10-26

第1の問題(Laravelのパッチバージョンが古い問題)

composer2.xがリリースされ、次第にcomposerの2系がビルドの際に落ちてくるようになりました。
その際、以下のようなエラーが出てきたかもしれません。

> @php artisan package:discover --ansi

In PackageManifest.php line 122:

  Undefined index: name

解決するには

Laravelのパッチバージョンを上げれば解決します。

いくつかのpull requestが各バージョンに対して行われています
https://github.com/laravel/framework/pull/32310

なぜこうなったのか

これはcomposer2.xvendor/composer/installed.jsonの形式が少し変わったせいです。

今まではpackagesがjson配列で定義されているだけでした。

[
    {
        "name": "asm89/stack-cors",
        "version": "v2.0.1",
        "version_normalized": "2.0.1.0",
        ...
    },
...
}

こちらが変更されpackagesというキーが上につくようになりました。

{
    "packages": [
        {
            "name": "barryvdh/laravel-debugbar",
            "version": "v3.2.8",
            "version_normalized": "3.2.8.0",
            ...
        },
    ]
...
}

影響はこのせいで、先程のPRでは$packages = $installed['packages'] ?? $installed;とすることで、packagesというキーがあればそれを使うように修正がされているのです。

第2の問題(packagist.jp問題)

一部の人だけですが、updateを行おうとするとこんな感じでエラーが出てくるかもしれません。

$ composer update --no-plugins
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires davejamesmiller/laravel-breadcrumbs 5.x, found davejamesmiller/laravel-breadcrumbs[5.3.1] in lock file but not in remote repositories, make sure you avoid updating this package to keep the one from lock file.

これは私の場合はですが、packagist.jpを設定していたからでした。

まずはこれを外します

composer config -g --unset repos.packagist

これで私はupdateをすることが出来ましたが、jpを使いたい人はいると思います。(現状ではpackagist.jpはv2に対応してないっぽい)
そんなときはcomposer.jsonのrepositoriesで設定をしましょう。

composer.json
    "repositories": [
        {
            "type": "composer",
            "url": "https://packagist.jp",
            "cannonical": false
        }
    ]

cannonical: falseは2.xからのオプションで公式のではないリポジトリを定義するためのものです。
packagist.jp自体は有志の方が作られたものであるため、falseにします。

69
45
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
69
45