Fixing "Laravel PackageManifest.php: Undefined index: name" in GitHub Actions
January 26, 2021
If you're running into the Laravel PackageManifest.php: Undefined index: name
error in Laravel, there are a couple of ways to fix it.
First, the issue is that Composer 2 changed the format of their installed.json
that is causing Laravel to not be able to find the installed packages. If you've been googling this error, you've probably already come across this issue, but here it is in case you haven't seen it yet: github.com/composer/issues/9340.
Laravel has updated to handle the new format, so the easiest way to fix it would be to update Laravel if you can: composer update laravel/framework
.
Here's the minimum version support for each Laravel release to get you the Composer 2 fix pic.twitter.com/8tvCK0jHYZ
— Jake (@jakebathman) October 26, 2020
If you can't update Laravel for whatever reason, you can roll back your Composer version to 1 by running composer self-update --1
. That will revert the installed.json
version back to a format your old Laravel version is comfortable with.
Fixing for GitHub Actions
If you're developing a package you may be testing with --prefer-lowest
and --prefer-stable
flags, so you can test the lowest version of a Laravel release and the most recent version. You also don't want to use Composer 1 all the time because it's quite a bit slower than Composer 2.
In that case, your workflow file may look a bit like this:
jobs: test: runs-on: ubuntu-latest strategy: matrix: laravel: [ 7.*, 8.* ] dependency-version: [ prefer-lowest, prefer-stable ] steps: - name: Install dependencies run: | composer require "laravel/framework:$@{{ matrix.laravel }}" "orchestra/testbench:$@{{ matrix.testbench }}" --no-interaction --no-update composer update --$@{{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute tests run: vendor/bin/phpunit
Here we're telling GitHub to run the tests on
- Laravel 7 lowest
- Laravel 7 stable
- Laravel 8 lowest
- Laravel 8 stable
The problem is that Laravel 7 --lowest has this undefined index
problem, and we don't want to update because we're specifically testing the oldest version here.
By adding an include
section, we can inject a variable whenever we're running the tests for 7 --lowest. Specifically, we're going to inject composer-version: --1
here, so when we're running 7 --lowest we'll use the old version of composer.
In our Install Dependencies
section we'll add a line to update Composer, taking our new variable into account: composer self-update $@{{ matrix.composer-version }}
.
jobs: test: runs-on: ubuntu-latest strategy: matrix: laravel: [ 7.*, 8.* ] dependency-version: [ prefer-lowest, prefer-stable ] include: - laravel: 7.* dependency-version: prefer-lowest # Use Composer 1 with Laravel 7 --lowest composer-version: --1 name: P$@{{ matrix.php }} - L$@{{ matrix.laravel }} - $@{{ matrix.dependency-version }} steps: - name: Install dependencies run: | composer self-update $@{{ matrix.composer-version }} composer require "laravel/framework:$@{{ matrix.laravel }}" "orchestra/testbench:$@{{ matrix.testbench }}" --no-interaction --no-update composer update --$@{{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute tests run: vendor/bin/phpunit
Now we're only using Composer 1 when we absolutely have to, so we get the speed/memory benefits of Composer 2 otherwise, and we've fixed the undefined index issue.
Hope that helps!