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

fcarpio's avatar

Target class auth does not exist in Container.php

Happens when running composer. I am upgrading from Laravel 7 to Laravel 8 and this is the offending composer.json file:


{
  "name": "laravel/laravel",
  "description": "The Laravel Framework.",
  "keywords": [
    "framework",
    "laravel"
  ],
  "license": "MIT",
  "type": "project",
  "require": {
    "php": "^7.3",
    "ext-zip": "*",
    "bensampo/laravel-enum": "^3.3",
    "brick/money": "~0.5.0",
    "doctrine/dbal": "^2.9",
    "fideloper/proxy": "^4.2",
    "firebase/php-jwt": "^5.2",
    "fruitcake/laravel-cors": "^2.0",
    "fzaninotto/faker": "^1.9.1",
    "guzzlehttp/guzzle": "^7.0.1",
    "illuminate/support": "^8.37",
    "jenssegers/agent": "^2.6",
    "kreait/laravel-firebase": "^3.0",
    "laravel/framework": "^8.0",
    "laravel/socialite": "^5.2",
    "laravel/telescope": "^4.4",
    "laravel/tinker": "^2.0",
    "laravel/ui": "^3.2",
    "league/flysystem-cached-adapter": "^1.1",
    "league/flysystem-sftp": "^1.0",
    "maatwebsite/excel": "^3.1",
    "mpdf/mpdf": "^8.0",
    "myriad/event-driven-service": "3.4.2",
    "myriad/notify-client-php": "^1.0",
    "myriad/squire-client": "^3.1.1",
    "org_heigl/ghostscript": "^2.3",
    "plivo/php-sdk": "^4.18",
    "rollbar/rollbar": "^1.3",
    "rossjcooper/laravel-hubspot": "^4.0",
    "socialiteproviders/microsoft-azure": "^3.0",
    "tymon/jwt-auth": "^1.0",
    "vanderlee/php-stable-sort-functions": "^2.0",
    "vyuldashev/laravel-openapi": "^0.24.1",
    "web-token/jwt-checker": "^2.2",
    "web-token/jwt-key-mgmt": "^2.2",
    "web-token/jwt-signature": "^2.2",
    "web-token/jwt-signature-algorithm-ecdsa": "^2.2"
  },
  "require-dev": {
    "barryvdh/laravel-ide-helper": "^2.4",
    "ddelnano/dredd-hooks-php": "^1.1",
    "facade/ignition": "^2.3.6",
    "filp/whoops": "~2.0",
    "mockery/mockery": "^1.3.1",
    "nunomaduro/collision": "^5.0",
    "phpunit/phpunit": "^9.0"
  },
  "autoload": {
    "files": [
      "bootstrap/helpers.php"
    ],
    "classmap": [
      "database/seeds",
      "database/factories"
    ],
    "psr-4": {
      "App\": "app/",
      "Database\UberFactories\": "database/uber-factories",
      "Database\Helpers\": "database/helpers"
    }
  },
  "autoload-dev": {
    "psr-4": {
      "Tests\": "tests/"
    }
  },
  "extra": {
    "laravel": {
      "dont-discover": [
        "laravel/telescope"
      ]
    }
  },
  "scripts": {
    "post-root-package-install": [
      "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
      "@php artisan key:generate"
    ],
    "post-autoload-dump": [
      "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
      "@php artisan package:discover"
    ]
  },
  "config": {
    "preferred-install": "dist",
    "sort-packages": true,
    "optimize-autoloader": true
  },
  "repositories": [
    {
      "type": "composer",
      "url": "https://satis.myriadmobile.com"
    }
  ],
  "minimum-stability": "dev",
  "prefer-stable": true
}

The actual error is:

In Container.php line 835:
                                       
  Target class [auth] does not exist.  
                                       

In Container.php line 833:
                             
  Class auth does not exist  
                             

Any help in resolving this issue will be greatly appreciated.

0 likes
10 replies
neilstee's avatar

@fcarpio

Happens when running composer

Are you running composer install or composer update?

neilstee's avatar

@fcarpio since you are upgrading, try: composer dump-autoload

If it still did not work:

  • delete your vendor folder and composer.lock file (I assumed you have git to revert when needed)
  • then run composer install
fcarpio's avatar

@neilstee Thank you for your response, I have tried all this. When I search for this issue these are the kind of answers I find but have not been able to fix it so far. This error happens every time I run composer, so 'composer dump-autoload' also generates this error. This is frustrating, to say the least.

vd's avatar

Check if the following directories exist and writable:

storage/framework/cache
storage/framework/sessions
storage/framework/views
bootstrap/cache
stephen waweru's avatar

@fcarpio how did you solve the error..am also working on solving the error and haven't found the solution

2 likes
eskimo's avatar

I experience the same error today, and it turns out that it might be something very different that is causing the error. In order to find exactly that's causing it, go to App\Exceptions\Handler and put dd($exception) in the the report function:

public function report(Throwable $exception) {
  dd($exception);
  ...
}

Now you can see exactly what's causing the error. In my case it was a small bug in one of the packages that I have included. Hope this helps!

15 likes
elvisisking's avatar

@eskimo or if you're using laravel 11 put this in bootstrap/app.php:

    ->withExceptions(function (Exceptions $exceptions) {
        $exceptions->report(function (Exception $e) {
            dd($e);
        });
mohmd_thabet's avatar

in my case it turned up as a package i removed that is still called in config/app.php file. so i used:

public function report(Throwable $exception) {
  dd($exception);
  ...
}
2 likes
ldanielduarte's avatar

I struggled with this for some time, in my case the middleware name was indeed wrong, like the machine was telling me since the beginning... Notice the change of line after the starting ' character in auth:sanctum middleware

Route
    ::prefix('configurations')
    ->name('configurations.')
    ->middleware(['
        auth:sanctum',
        config('jetstream.auth_session'),
        'verified',
    ])

Please or to participate in this conversation.