[Laravel]composer removeで「ansi handling the post-autoload-dump event returned with error」エラー対象法

[Laravel]composer removeで「ansi handling the post-autoload-dump event returned with error」エラー対象法
2021年04月27日2023年10月10日

ローカル環境で不要になったパッケージを削除しようと「composer remove」を実行したところ、最後の最後でエラーが発生しました。

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

どうやらパッケージを削除後のdump autoload処理で失敗している模様。

発生したエラー

今回Laravelのデバッカーのパッケージを削除しようとしたところ下記のエラーが発生。

# /usr/local/bin/composer remove barryvdh/laravel-debugbar
Do not run Composer as root/super user! See https://getcomposer.org/root for details
barryvdh/laravel-debugbar is not required in your composer.json and has not been removed
Dependency "laravel/framework" is also a root requirement, but is not explicitly allowed. Ignoring.
Dependency "laravel/framework" is also a root requirement, but is not explicitly allowed. Ignoring.
Dependency "laravel/framework" is also a root requirement, but is not explicitly allowed. Ignoring.
Loading composer repositories with package information
Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2 is now available and you should upgrade. See https://getcomposer.org/2
Updating dependencies (including require-dev)
Package operations: 1 install, 6 updates, 2 removals
  - Removing maximebf/debugbar (v1.16.5)
  - Removing barryvdh/laravel-debugbar (v3.4.2)
  - Installing symfony/polyfill-php80 (v1.22.1): Loading from cache
  - Updating psr/log (1.1.0 => 1.1.3): Downloading (100%)
  - Updating symfony/debug (v4.2.5 => v4.4.20): Loading from cache
  - Updating symfony/finder (v4.2.5 => v4.4.20): Loading from cache
  - Updating symfony/polyfill-php72 (v1.11.0 => v1.22.1): Loading from cache
  - Updating symfony/polyfill-mbstring (v1.11.0 => v1.22.1): Loading from cache
  - Updating symfony/var-dumper (v4.2.5 => v4.4.21): Downloading (100%)
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating optimized autoload files
Deprecation Notice: Class Egulias\EmailValidator\Exception\ExpectedQPair located in ./vendor/egulias/email-validator/EmailValidator/Exception/ExpectingQPair.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

In ProviderRepository.php line 208:

  Class 'Barryvdh\Debugbar\ServiceProvider' not found


Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

エラーの内容を見ると「Class 'Barryvdh\Debugbar\ServiceProvider' not found」とファイルが無いよというエラーでした。

原因は、削除したパッケージがどこかのファイルで呼ばれていて、dump autoload処理をしようとしたところ、ファイルが無いよというエラーのようです。

エラーの対処法

エラーの対処方法は簡単で、インストールしていたパッケージの記述を削除します。

Laravelの場合、なにかパッケージを追加したあと、app.phpファイルにproviders項目に記述が無いか確認しましょう。

記述がある場合は、削除します。
(今回はprovidersに記述があったためapp.phpを修正しています。)

project/config/app.php
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/

'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Auth\AuthServiceProvider::class,

    ~省略~
    /*
     * Package Service Providers...
     */

    /*
     * Application Service Providers...
     */
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,
    // ↓↓↓今回「barryvdh/laravel-debugbar」のパッケージを削除するため削除 or コメントアウトして無効にする
    // Barryvdh\Debugbar\ServiceProvider::class,

],

削除ができたら、再度compsoer removeコマンドを実行します。

# /usr/local/bin/composer remove barryvdh/laravel-debugbar
Do not run Composer as root/super user! See https://getcomposer.org/root for details
barryvdh/laravel-debugbar is not required in your composer.json and has not been removed
Package "barryvdh/laravel-debugbar" listed for update is not installed. Ignoring.
Loading composer repositories with package information
Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2 is now available and you should upgrade. See https://getcomposer.org/2
Updating dependencies (including require-dev)
Nothing to install or update
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
Deprecation Notice: Class Egulias\EmailValidator\Exception\ExpectedQPair located in ./vendor/egulias/email-validator/EmailValidator/Exception/ExpectingQPair.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: encore/laravel-admin
Discovered Package: fideloper/proxy
Discovered Package: laravel-admin-ext/log-viewer
Discovered Package: laravel-admin-ext/media-manager
Discovered Package: laravel-admin-ext/scheduling
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
6 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

エラーが出なければ、完了となります。

コメント

コメントを残す

お名前(任意)
コメント:新規