You encounter the Laravel PackageManifest.php: Undefined index: name error when Laravel tries to read the composer.json of installed packages but encounters a package that doesn’t have the expected “name” key.
How to fix the error?
Here are three approved solutions that you can use to fix the error.
- The simple fix for the error is to use this command: composer update. This will update the composer.lock file.
- If you can’t upgrade Laravel, you can just stay with Composer 1 by running this command:
composer self-update --1
- Delete the composer.lock file and Install dependencies using this command.
If you search for the error on the internet, you will find some solutions, like downgrading the composer version or packages to be compatible with the current project, but this is a temporary solution and won’t work well in the long term.
Not recommended way to fix the error
Open this file: vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php
Find this code of line and comment on it:
$packages = json_decode($this->files->get($path), true);
Add two new lines after the above-commented line.
$installed = json_decode($this->files->get($path), true); $packages = $installed['packages'] ?? $installed;
This will fix the error, but this is really not the recommended approach to use in your already established Laravel project.
I recommend you never change your composer version or the Laravel core files directly because if you do, third-party packages won’t be compatible with your modified version, and it will start throwing expected errors, which will cause chaos in your project.
The best and most efficient solution is to delete the composer.lock and install the dependencies using the “composer install” command.