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

119,284

Solution 1

This is how I solved this after an upgrade from laravel version 6.x - 7.x:

In App\Exceptions\Handler changed

//Use Exception;
Use Throwable;

Then methods to accept instances of Throwable instead of Exceptions as follows:

//public function report(Exception$exception);
public function report(Throwable $exception);

//public function render($request, Exception $exception);
public function render($request, Throwable $exception);

In config\session.php:

//'secure' => env('SESSION_SECURE_COOKIE', false),
'secure' => env('SESSION_SECURE_COOKIE', null),

Then run composer update

Solution 2

I solved the problem this way:

cd bootstrap/cache/
rm -rf *.php

The bootstrap directory contains the app.php file that initializes the structure. This directory also houses a cache directory that contains structure-generated files for performance optimization, such as files and route cache services. Laravel stores configuration files, provider, and cached services to optimize the fetching of this information. The problem with me was when the other developer ran the 'php artisan config: cache' command on your machine and since the cache folder contains files that can be deleted, I deleted them and solved the problem.

Solution 3

If this happened after Laravel update from 6.x to 7.x, then this could be due to the update of Symfony. See the upgrade guide of this part: https://laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades

Solution 4

I was upgrading my Laravel from 5.8 to 8.0 and I got this error.

So my fixes were

  1. As @nobuhiroharada mentioned that I had missed .env file in my project

  2. Second is that Laravel removed Exception and replaced it with Throwable. So we need to fix that in our app\Exceptions\Handler.php. One can refer Medium.com for the error fix.

  3. In the upgrade guide of Laravel 8.x you need to update the dependencies like this

  4. Next, in your composer.json file, remove classmap block from the autoload section and add the new namespaced class directory mappings:

"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Factories\\": "database/factories/",
        "Database\\Seeders\\": "database/seeders/"
    }
},
  1. Finally from bootstrap\cache delete the cache files and run composer update.

These 5 steps might help you remove the error you are facing in your Laravel Project.

Solution 5

This happens because you have upgraded to Laravel 7.

To fix it, update app/Exceptions/Handler.php like so:

<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable; // <-- ADD THIS

class Handler extends ExceptionHandler
{
    public function report(Throwable $exception) // <-- USE Throwable HERE
    {
        parent::report($exception);
    }
    public function render($request, Throwable $exception) // AND HERE
    {
        return parent::render($request, $exception);
    }
}

This is documented in the official upgrade guide here:

https://laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades

Share:
119,284

Related videos on Youtube

Ghyath Darwish
Author by

Ghyath Darwish

Updated on July 08, 2022

Comments

  • Ghyath Darwish
    Ghyath Darwish almost 2 years

    I moved my project from desk to another.
    When I run php artisan it does not work.

    I tried to run composer update, but it returns the error

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

    • Barry
      Barry almost 5 years
      For me it was caused by folder permissions. chown -R u:g, and chmod -R 755 did the job for me.
    • ctf0
      ctf0 over 3 years
      it was an issue in a trait but i couldnt find no matter what, using something like packagist.org/packages/nunomaduro/larastan can catch that
    • user123456
      user123456 about 2 years
      I tried all the soultion and nothing worked I am running laravel 4.2.10 and php 7 @Ghyath Darwish
  • Javier Larroulet
    Javier Larroulet over 5 years
    It would help to explain what that is and why did it solve the problem
  • Samuel Terra
    Samuel Terra over 5 years
    The bootstrap directory contains the app.php file that initializes the structure. This directory also houses a cache directory that contains structure-generated files for performance optimization, such as files and route cache services. Laravel stores configuration files, provider, and cached services to optimize the fetching of this information. The problem with me was when the other developer ran the 'php artisan config: cache' command on your machine and since the cache folder contains files that can be deleted, I deleted them and solved the problem.
  • Ben Everard
    Ben Everard about 4 years
    Thanks for posting this, missed this part of the upgrade guide and got caught out.
  • paulmartimx
    paulmartimx about 4 years
    Thanks, this is the correct answer when upgrading, as said in upgrade guide: laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades
  • MT_Shikomba
    MT_Shikomba over 3 years
    This worked for me too. Thanks. I upgraded from laravel 6 to laravel 7.
  • Taylor Foster
    Taylor Foster about 3 years
    This is the fix
  • М.Б.
    М.Б. about 3 years
    DON'T RUN THIS! This is really dangerous command written as it is! For example, if he's not in the project root directory, cd will fail, but rm command is going to execute! Run this either as rm -rf bootstrap/cache/* or cd bootstrap/cache && rm -rf *php
  • Healyhatman
    Healyhatman over 2 years
    Mine was a missing bracket in Handler.php so thanks
  • Tom Mwenda
    Tom Mwenda about 2 years
    This solved my problems after hours of searching
  • Sniper
    Sniper about 2 years
    Every sol, on this page doesn't seem to work for me. What could be the reason? Any ideas?
  • Erich García
    Erich García about 2 years
    Yeah, this is the definitive answer.