Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

syntaxerron's avatar

Error when deploying Laravel app to Heroku

I tried to deploy a Laravel application on Heroku, unfortunately, I got this error: Class 'Barryvdh\Debugbar\ServiceProvider' not found

I tried removing the package and perform composer update and composer dump-autoload. I also deleted the config.php inside the bootstrap\cache folder but the error still exists. I also performed php artisan config:clear, php artisan cache:clear but nothing happened.

This is my composer.json:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2.5",
        "ajcastro/eager-load-pivot-relations": "^0.2.2",
        "anlutro/l4-settings": "^1.0",
        "doctrine/dbal": "^2.12",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^6.3",
        "laravel/framework": "^7.24",
        "laravel/sanctum": "^2.7",
        "laravel/tinker": "^2.0",
        "laravel/ui": "^2.2",
        "maatwebsite/excel": "^3.1",
        "psalm/plugin-laravel": "^1.4",
        "spatie/laravel-activitylog": "^3.16",
        "spatie/laravel-permission": "^3.17"
    },
    "require-dev": {
        "beyondcode/laravel-query-detector": "^1.5",
        "facade/ignition": "^2.0",
        "fzaninotto/faker": "^1.9.1",
        "mockery/mockery": "^1.3.1",
        "nunomaduro/collision": "^4.1",
        "phpunit/phpunit": "^8.5",
        "vimeo/psalm": "^4.6"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "files": [
            "app/helpers.php"
        ]
    },
    "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"
        ]
    }
}
0 likes
6 replies
tykus's avatar

Is the class specifically referenced somewhere in your code; e.g. the providers array in the config/app.php file?

syntaxerron's avatar

I also removed it from there, Barryvdh\Debugbar\ServiceProvider::class in config/app.php

syntaxerron's avatar

Is there anything else where this Laravel Debugbar package could be referenced to?

neoish's avatar

Can you post the full error stack?

syntaxerron's avatar

This is what I get on the last part after git push heroku master:

remote:        composer/package-versions-deprecated: Generating version class...
remote:        composer/package-versions-deprecated: ...done generating version class
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:
remote:       In ProviderRepository.php line 208:
remote:
remote:          Class 'Barryvdh\Debugbar\ServiceProvider' not found
remote:
remote:
remote:        Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
remote:  !     WARNING: There was a class not found error in your code
remote:
remote:  !     ERROR: Dependency installation failed!
remote:  !
remote:  !     The 'composer install' process failed with an error. The cause
remote:  !     may be the download or installation of packages, or a pre- or
remote:  !     post-install hook (e.g. a 'post-install-cmd' item in 'scripts')
remote:  !     in your 'composer.json'.
remote:  !
remote:  !     Typical error cases are out-of-date or missing parts of code,
remote:  !     timeouts when making external connections, or memory limits.
remote:  !
remote:  !     Check the above error output closely to determine the cause of
remote:  !     the problem, ensure the code you're pushing is functioning
remote:  !     properly, and that all local changes are committed correctly.
remote:  !
remote:  !     For more information on builds for PHP on Heroku, refer to
remote:  !     https://devcenter.heroku.com/articles/php-support
remote:  !
remote:  !     REMINDER: the following warnings were emitted during the build;
remote:  !     check the details above, as they may be related to this error:
remote:  !     - There was a class not found error in your code
remote:
remote:  !     Push rejected, failed to compile PHP app.
remote: 
remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: fad88e3a5b13f29809ae06e0b7ec0a692196cb0b
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version fad88e3a5b13f29809ae06e0b7ec0a692196cb0b
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote: 
remote: !       Push rejected to guarded-bastion-75324.
remote:
To https://git.heroku.com/guarded-bastion-75324.git
 ! [remote rejected]   master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/guarded-bastion-75324.git'

martinbean's avatar

@loose1eaf You’re calling the class somewhere. Do a global find in your project for “Barryvdh”, remove the reference, commit the change, and then trying pushing again.

Please or to participate in this conversation.