I am created new laravel project, ran composer update
and get this error:
> @php artisan package:discover
Fatal error: Uncaught Error: Call to undefined method ComposerRepositoryPlatformRepository::isPlatformPackage() in /var/www/app/vendor/composer/composer/src/Composer/Json/JsonManipulator.php:139
Stack trace:
#0 /var/www/app/vendor/composer/composer/src/Composer/Json/JsonManipulator.php(163): ComposerJsonJsonManipulator->ComposerJson{closure}('php')
#1 [internal function]: ComposerJsonJsonManipulator->ComposerJson{closure}('php', 'matviib/telegra...')
#2 /var/www/app/vendor/composer/composer/src/Composer/Json/JsonManipulator.php(164): uksort(Array, Object(Closure))
#3 /var/www/app/vendor/composer/composer/src/Composer/Json/JsonManipulator.php(119): ComposerJsonJsonManipulator->sortPackages(Array)
#4 /var/www/app/vendor/php-http/discovery/src/Composer/Plugin.php(445): ComposerJsonJsonManipulator->addLink('require', 'php-http/messag...', '*', true)
#5 /var/www/app/vendor/php-http/discovery/src/Composer/Plugin.php(176): HttpDiscoveryComposerPlugin->updateComposerJson(Array, true)
#6 [internal function]: Http in /var/www/app/vendor/composer/composer/src/Composer/Json/JsonManipulator.php on line 139
What is the reason of this error? Looks like some problem inside Composer code so I don’t even know what to do with this.
2
Answers
It seems you’re facing an issue with Composer, likely related to version incompatibility or cache problems. Let’s break down the common causes and solutions:
Older Composer versions might lack features needed by newer packages.
to fix this you can Upgrade Composer to the latest version:
Corrupted cache files can cause errors.To fix this you can clear the Composer cache:
Your vendor directory (where dependencies live) might be faulty.You can remove it and the composer.lock file, then reinstall:
Your composer.json might list incompatible packages. Carefully examine the dependencies, making sure they work together.
Your PHP version might not match the requirements of your packages.
Check your PHP version:
Upgrade PHP if needed, or adjust package versions in composer.json to match your PHP.
Preventing Future Issues
Keep Composer Updated: Regularly run composer self-update to get the latest features and bug fixes.
Use composer.lock: Lock dependencies to ensure consistency across environments.
Follow these steps
composer self-update
composer clear-cache
rm -rf vendor/
composer install
composer outdated
composer update
php artisan package:discover