statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.58k stars 489 forks source link

Target class [blade.compiler] does not exist. #9940

Closed hlorofos closed 2 months ago

hlorofos commented 2 months ago

Bug description

I'm trying to install Statamic CMS over my existing application, but when I run php artisan it failed with the following stack trace

#0 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Container/Container.php(912): ReflectionClass->__construct('blade.compiler')
#1 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Container/Container.php(795): Illuminate\\Container\\Container->build('blade.compiler')
#2 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(957): Illuminate\\Container\\Container->resolve('blade.compiler', Array, true)
#3 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Container/Container.php(731): Illuminate\\Foundation\\Application->resolve('blade.compiler', Array)
#4 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(942): Illuminate\\Container\\Container->make('blade.compiler', Array)
#5 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Container/Container.php(1454): Illuminate\\Foundation\\Application->make('blade.compiler')
#6 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(237): Illuminate\\Container\\Container->offsetGet('blade.compiler')
#7 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(208): Illuminate\\Support\\Facades\\Facade::resolveFacadeInstance('blade.compiler')
#8 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(349): Illuminate\\Support\\Facades\\Facade::getFacadeRoot()
#9 /Users/j/Herd/veryimportant/vendor/statamic/cms/src/Providers/ViewServiceProvider.php(180): Illuminate\\Support\\Facades\\Facade::__callStatic('directive', Array)
#10 /Users/j/Herd/veryimportant/vendor/statamic/cms/src/Providers/ViewServiceProvider.php(46): Statamic\\Providers\\ViewServiceProvider->registerBladeDirectives()
#11 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(788): Statamic\\Providers\\ViewServiceProvider->register()
#12 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Support/AggregateServiceProvider.php(31): Illuminate\\Foundation\\Application->register(Object(Statamic\\Providers\\ViewServiceProvider))
#13 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(788): Illuminate\\Support\\AggregateServiceProvider->register()
#14 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(75): Illuminate\\Foundation\\Application->register(Object(Statamic\\Providers\\StatamicServiceProvider))
#15 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(765): Illuminate\\Foundation\\ProviderRepository->load(Array)
#16 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php(17): Illuminate\\Foundation\\Application->registerConfiguredProviders()
#17 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(263): Illuminate\\Foundation\\Bootstrap\\RegisterProviders->bootstrap(Object(Illuminate\\Foundation\\Application))
#18 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(447): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#19 /Users/j/Herd/veryimportant/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(199): Illuminate\\Foundation\\Console\\Kernel->bootstrap()
#20 /Users/j/Herd/veryimportant/artisan(35): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))

Important lines are here

#9 /Users/j/Herd/veryimportant/vendor/statamic/cms/src/Providers/ViewServiceProvider.php(180): Illuminate\\Support\\Facades\\Facade::__callStatic('directive', Array)
#10 /Users/j/Herd/veryimportant/vendor/statamic/cms/src/Providers/ViewServiceProvider.php(46): Statamic\\Providers\\ViewServiceProvider->registerBladeDirectives()

It tries to register it's blade directives but failed.

How to reproduce

this happened on the existing project on Laravel 10.48.8 when I tried to add Statamic by running composer require statamic/cms --with-dependencies

Logs

No response

Environment

Laravel 10.48.8
Statamic 4.57.0

Installation

Existing Laravel app

Antlers Parser

None

Additional details

No response

hlorofos commented 2 months ago

Workaround is: remove statamic from auto-discovery by adding the following to composer.json

"extra": {
    "laravel": {
      "dont-discover": [
        "statamic/cms"
      ]
    }
  }

manually add \Statamic\Providers\StatamicServiceProvider::class, to the end of providers list in config/app.php for Laravel Framework. Now its possible to run php artisan command again

duncanmcclean commented 2 months ago

Do you have anything custom in your AppServiceProvider or your ViewServiceProvider?

jasonvarga commented 2 months ago

I see the issue.

In https://github.com/statamic/cms/pull/9732 it should have been added to boot, not register.