2
votes

after upgrading Laravel according to the docs to v7 I ran composer update. Then I'm getting this:

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

This is my composer.json file:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "guzzlehttp/guzzle": "^6.5",
        "kitetail/zttp": "^0.6.0",
        "laravel/framework": "^7.0",
        "laravel/tinker": "^2.0",
        "laravel/telescope": "^2.1",
        "laravelcollective/html": "^6.0",
        "livewire/livewire": "^0.7.4",
        "spatie/laravel-html": "^2.24",
        "spatie/laravel-permission": "^3.0.0"
    },
    "require-dev": {
        "barryvdh/laravel-debugbar": "^3.2",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "laravel/ui": "^2.0",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^4.1",
        "phpunit/phpunit": "^7.5"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

I'm confused right now. It even seems that php artisan doesn't do anything in this project. In other projects it's just working fine. Any idea how this could be fixed?

Edit: Some of the answers provided suggestions. I'm getting the following using Laragon:

PS C:\laragon\www\attila> composer update
Updating dependencies (including require-dev)
Package operations: 0 installs, 4 updates, 0 removals
  - Updating laravel/framework (v7.0.1 => v7.0.2): Downloading (100%)
  - Updating spatie/laravel-permission (3.10.1 => 3.11.0): Downloading (100%)
  - Updating laravel/ui (v2.0.0 => v2.0.1): Downloading (100%)
  - Updating nunomaduro/collision (v4.1.1 => v4.1.2): Downloading (100%)
Package moontoast/math is abandoned, you should avoid using it. Use brick/math instead.
Writing lock file
Generating optimized autoload files
> @php artisan package:discover --ansi
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
PS C:\laragon\www\attila> php artisan package:discover --ansi
PS C:\laragon\www\attila>
6
Try running php artisan package:discover and see the error output from that. That might indicate what you are missing. - Repox
@LewisTudor From version? - Wahyu Kristianto
Remove the @ in front of the command to get the actual error and post it here. - Jerodev
@WahyuKristianto I was upgrading vom Laravel 6 to Laravel 7. - Lewis Tudor
@Repox I updated the question unfortunately I don't get any output. - Lewis Tudor

6 Answers

10
votes

After deleting all the cache in bootstrap & storage/framework folders, still no results.

Running the php artisan --help returns some errors, this gave me a hint where the problem is.

After checking the Upgrade Guide I solved the issue, for me it was:

  • Changes in App\Exceptions\Handler methods
  • install require laravel/ui package
3
votes

For me, it was a very simple error and fix. The relevant portion of the 7.x Upgrade docs says the following:

Symfony 5 Related Upgrades Likelihood Of Impact: High

Laravel 7 utilizes the 5.x series of the Symfony components. Some minor changes to your application are required to accommodate this upgrade.

First, the report, render, shouldReport, and renderForConsole methods of your application's App\Exceptions\Handler class should accept instances of the Throwable interface instead of Exception instances:

use Throwable;

public function report(Throwable $exception); 
public function shouldReport(Throwable $exception);
public function render($request, Throwable $exception);
public function renderForConsole($output, Throwable $exception);

Relevant file: ./App/Exceptions/Handler.php Change: convert instances of "Exception" to "Throwable" (editor search and replace)

So, basically, once I put the change in place, 'php artisan' started to work again. This included the package:discover command in the OP's composer.json (and mine).

I tried putting it back to Exception, and the artisan command would fail to do anything. Change the occurrences of Exception to Throwable, and everything works. (My application only had the first two functions defined, though.)

So, it pays to pay attention to the documentation.

2
votes

You must delete old files (cache). This commands should works:

cd bootstrap/cache/
rm -rf *.php
composer update

If you are work on regular user, add sudo before each command.

1
votes

Try this :

cd bootstrap/cache/
rm -rf *.php

Then composer update again.

0
votes

After following the upgrade guide in the docs some folks in the Laravel Discord chat guided me to update the Symfony 5 Related Upgrades.

I had to remove telescope (which I'm not using) too.

0
votes

If you are using Laravel 7 for some reason while your install composer 3.x installed on your system. use following command:

composer require laravel/ui ^2.0