0
votes

When I want to deploying my app to production. I simply run

composer install --no-dev --optimize-autoloader

Which will result an error.

In TelescopeServiceProvider.php line 10: Class 'Laravel\Telescope\TelescopeApplicationServiceProvider' not found

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

1
In composer.json, do you put "laravel/telescope" in require or require-dev section? - Quynh Xuan Nguyen
@QuynhXuanNguyen Yes I have put "laravel/telescope" in compser.json on require-dev section - Player 2nd
just run composer install - Kamlesh Paul
@KamleshPaul but i don't want the telescope installed on production - Player 2nd
In config/app.php, does TelescopeServiceProvider exists inside 'providers' key? - Quynh Xuan Nguyen

1 Answers

3
votes
  1. Remove App\Providers\TelescopeServiceProvider::class from config/app.php because all providers inside config/app.php is automatically loaded. But in your production environment, laravel/telescope isn't installed that means Laravel\Telescope\TelescopeApplicationServiceProvider is undefined and App\Providers\TelescopeServiceProvider can not extend an undefined class.

  2. Register App\Providers\TelescopeServiceProvider::class manually inside app/Providers/AppServiceProviders.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Laravel\Telescope\TelescopeApplicationServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        if (class_exists(TelescopeApplicationServiceProvider::class)) {
            $this->app->register(TelescopeServiceProvider::class);
        }
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}