Acorn & PHP 8.1 publicPath error

Hi there,

In my latest full stack Roots project, I’m using php 8.1 on my droplet, locally I was still on php 8.0 but I set the platform php option to 8.1 in my composer.json. I did get a warning, but my Sage theme was running fine.

However last week I switched to 8.1 with brew-php-switcher and suddenly I’m starting to get this error in my theme (admin & front-end):

Fatal error: Declaration of Illuminate\Foundation\Application::publicPath() must be compatible with Illuminate\Contracts\Foundation\Application::publicPath($path = '') in /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Application.php on line 453

This happens when Acorn 3.2 is installed in the bedrock folder. I tried:

  • Removing app/cache folder
  • Running rm -rf ./vendor && rm composer.lock && composer install
  • Running wp @development acorn optimize:clear & wp @development acorn config:clear

Nothing works?
When I remove "roots/acorn": "^3.2" and run composer require roots/acorn, it installs the dev-laravel-10 acorn branch, but then I get errors when running any Acorn WP-CLI command:

In ProviderRepository.php line 109:
Undefined array key "providers"

and even more errors in browser:

Uncaught ReflectionException: Class "view" does not exist in /srv/www/example.com/current/vendor/illuminate/container/Container.php:912 Stack trace: #0 /srv/www/example.com/current/vendor/illuminate/container/Container.php(912): ReflectionClass->__construct('view') #1 /srv/www/example.com/current/vendor/illuminate/container/Container.php(795): Illuminate\Container\Container->build('view') #2 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Application.php(933): Illuminate\Container\Container->resolve('view', Array, true) #3 /srv/www/example.com/current/vendor/illuminate/container/Container.php(731): Illuminate\Foundation\Application->resolve('view', Array) #4 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Application.php(918): Illuminate\Container\Container->make('view', Array) #5 /srv/www/example.com/current/vendor/illuminate/container/Container.php(1454): Illuminate\Foundation\Application->make('view') #6 /srv/www/example.com/current/vendor/illuminate/support/Facades/Facade.php(236): Illuminate\Container\Container->offsetGet('view') #7 /srv/www/example.com/current/vendor/illuminate/support/Facades/Facade.php(207): Illuminate\Support\Facades\Facade::resolveFacadeInstance('view') #8 /srv/www/example.com/current/vendor/illuminate/support/Facades/Facade.php(347): Illuminate\Support\Facades\Facade::getFacadeRoot() #9 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Exceptions/RegisterErrorViewPaths.php(18): Illuminate\Support\Facades\Facade::__callStatic('replaceNamespac...', Array) #10 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Exceptions/Handler.php(661): Illuminate\Foundation\Exceptions\RegisterErrorViewPaths->__invoke() #11 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Exceptions/Handler.php(642): Illuminate\Foundation\Exceptions\Handler->registerErrorViewPaths() #12 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Exceptions/Handler.php(573): Illuminate\Foundation\Exceptions\Handler->renderHttpException(Object(Symfony\Component\HttpKernel\Exception\HttpException)) #13 /srv/www/example.com/current/vendor/roots/acorn/src/Roots/Acorn/Exceptions/Handler.php(28): Illuminate\Foundation\Exceptions\Handler->prepareResponse(Object(Illuminate\Http\Request), Object(Symfony\Component\HttpKernel\Exception\HttpException)) #14 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(217): Roots\Acorn\Exceptions\Handler->render(Object(Illuminate\Http\Request), Object(ErrorException)) #15 /srv/www/example.com/current/vendor/roots/acorn/src/Roots/Acorn/Bootstrap/HandleExceptions.php(92): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(ErrorException)) #16 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(194): Roots\Acorn\Bootstrap\HandleExceptions->renderHttpResponse(Object(ErrorException)) #17 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(ErrorException)) #18 {main} Next Illuminate\Contracts\Container\BindingResolutionException: Target class [view] does not exist. in /srv/www/example.com/current/vendor/illuminate/container/Container.php:914 Stack trace: #0 /srv/www/example.com/current/vendor/illuminate/container/Container.php(795): Illuminate\Container\Container->build('view') #1 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Application.php(933): Illuminate\Container\Container->resolve('view', Array, true) #2 /srv/www/example.com/current/vendor/illuminate/container/Container.php(731): Illuminate\Foundation\Application->resolve('view', Array) #3 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Application.php(918): Illuminate\Container\Container->make('view', Array) #4 /srv/www/example.com/current/vendor/illuminate/container/Container.php(1454): Illuminate\Foundation\Application->make('view') #5 /srv/www/example.com/current/vendor/illuminate/support/Facades/Facade.php(236): Illuminate\Container\Container->offsetGet('view') #6 /srv/www/example.com/current/vendor/illuminate/support/Facades/Facade.php(207): Illuminate\Support\Facades\Facade::resolveFacadeInstance('view') #7 /srv/www/example.com/current/vendor/illuminate/support/Facades/Facade.php(347): Illuminate\Support\Facades\Facade::getFacadeRoot() #8 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Exceptions/RegisterErrorViewPaths.php(18): Illuminate\Support\Facades\Facade::__callStatic('replaceNamespac...', Array) #9 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Exceptions/Handler.php(661): Illuminate\Foundation\Exceptions\RegisterErrorViewPaths->__invoke() #10 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Exceptions/Handler.php(642): Illuminate\Foundation\Exceptions\Handler->registerErrorViewPaths() #11 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Exceptions/Handler.php(573): Illuminate\Foundation\Exceptions\Handler->renderHttpException(Object(Symfony\Component\HttpKernel\Exception\HttpException)) #12 /srv/www/example.com/current/vendor/roots/acorn/src/Roots/Acorn/Exceptions/Handler.php(28): Illuminate\Foundation\Exceptions\Handler->prepareResponse(Object(Illuminate\Http\Request), Object(Symfony\Component\HttpKernel\Exception\HttpException)) #13 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(217): Roots\Acorn\Exceptions\Handler->render(Object(Illuminate\Http\Request), Object(ErrorException)) #14 /srv/www/example.com/current/vendor/roots/acorn/src/Roots/Acorn/Bootstrap/HandleExceptions.php(92): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(ErrorException)) #15 /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(194): Roots\Acorn\Bootstrap\HandleExceptions->renderHttpResponse(Object(ErrorException)) #16 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(ErrorException)) #17 {main} thrown in /srv/www/example.com/current/vendor/illuminate/container/Container.php on line 914

What am I missing here? Acorn is compatible with php 8.1 right? Any help is appreciated.

Thanks!

1 Like

Do you want to install acorn as plugin or as theme dependency? On first glance it appears to me that you installed acorn as plugin and as theme dependency at the same time.
Check the site composer.json and the theme composer.json for acorn.

I’m installing it as a composer dependency in the site directory and I double checked, Acorn not in my theme composer.json:

  "require": {
    "php": "^8.0",
    "log1x/acf-composer": "^2.0",
    "log1x/navi": "^2.0",
    "log1x/poet": "^2.0",
    "log1x/sage-directives": "^1.1",
    "log1x/sage-svg": "^1.0",
    "spatie/laravel-google-fonts": "^1.2"
  },

I think I fixed it by specifying php to 8.0 in my theme’s composer.json:

  "config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "sort-packages": true,
    "platform": {
      "php": "8.0"
    }
  },

Not sure why this is neccessary though?

You shouldn’t have to do any platform specifications. Is PHP-CLI using 8.1 (php -v)? Acorn v3.2 works on PHP 8.1 & 8.2.

dev-laravel-10 is broken and not ready for any kind of use. Unless you dropped minimum-stability or set preferred-install I’m genuinely confused on how that would ever get pulled in without specifying it. It is not tagged.

I highly suggest https://herd.laravel.com/ and something like https://dbngin.com/ instead of managing PHP with Homebrew.

1 Like

Thanks, Herd looks really nice, gonna use that from now on!
Yes, php -v was returning 8.1.
Gonna try this later and I’ll report back!

So I’m using Herd now for managing php versions and currently I’m on:

PHP 8.1.24 (cli) (built: Sep 29 2023 00:22:23) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.24, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.24, Copyright (c), by Zend Technologies

The weird thing is, when I don’t specify the platform php in my theme’s composer.json it installs the following versions:

Installing dependencies from lock file (including require-dev)
Package operations: 23 installs, 0 updates, 0 removals
  - Installing guzzlehttp/promises (2.0.1): Extracting archive
  - Installing ralouphie/getallheaders (3.0.3): Extracting archive
  - Installing psr/http-message (2.0): Extracting archive
  - Installing psr/http-factory (1.0.2): Extracting archive
  - Installing guzzlehttp/psr7 (2.6.1): Extracting archive
  - Installing johnbillion/args (1.8.0): Extracting archive
  - Installing doctrine/inflector (2.0.8): Extracting archive
  - Installing stoutlogic/acf-builder (v1.12.0): Extracting archive
  - Installing log1x/acf-composer (v2.1.0): Extracting archive
  - Installing log1x/navi (v2.0.4): Extracting archive
  - Installing johnbillion/extended-cpts (5.0.5): Extracting archive
  - Installing log1x/poet (v2.0.8): Extracting archive
  - Installing log1x/sage-directives (v1.1.9): Extracting archive
  - Installing log1x/sage-svg (v1.1.1): Extracting archive
  - Installing psr/container (2.0.2): Extracting archive
  - Installing psr/http-client (1.0.3): Extracting archive
  - Installing psr/simple-cache (3.0.0): Extracting archive
  - Installing illuminate/contracts (v10.25.2): Extracting archive
  - Installing spatie/laravel-package-tools (1.16.1): Extracting archive
  - Installing symfony/deprecation-contracts (v3.3.0): Extracting archive
  - Installing guzzlehttp/guzzle (7.8.0): Extracting archive
  - Installing spatie/laravel-google-fonts (1.2.3): Extracting archive
  - Installing squizlabs/php_codesniffer (3.7.1): Extracting archive

Which results in that publicPath error again:

Fatal error: Declaration of Illuminate\Foundation\Application::publicPath() must be compatible with Illuminate\Contracts\Foundation\Application::publicPath($path = '') in /srv/www/example.com/current/vendor/roots/acorn/src/Illuminate/Foundation/Application.php on line 453

When I add:

    "platform": {
      "php": "8.0"
    }

It installs the following versions:

Installing dependencies from lock file (including require-dev)
Package operations: 23 installs, 0 updates, 0 removals
  - Installing guzzlehttp/promises (2.0.1): Extracting archive
  - Installing ralouphie/getallheaders (3.0.3): Extracting archive
  - Installing psr/http-message (2.0): Extracting archive
  - Installing psr/http-factory (1.0.2): Extracting archive
  - Installing guzzlehttp/psr7 (2.6.1): Extracting archive
  - Installing johnbillion/args (1.8.0): Extracting archive
  - Installing doctrine/inflector (2.0.8): Extracting archive
  - Installing stoutlogic/acf-builder (v1.12.0): Extracting archive
  - Installing log1x/acf-composer (v2.1.0): Extracting archive
  - Installing log1x/navi (v2.0.4): Extracting archive
  - Installing johnbillion/extended-cpts (5.0.5): Extracting archive
  - Installing log1x/poet (v2.0.8): Extracting archive
  - Installing log1x/sage-directives (v1.1.9): Extracting archive
  - Installing log1x/sage-svg (v1.1.1): Extracting archive
  - Installing psr/container (1.1.2): Extracting archive
  - Installing psr/http-client (1.0.3): Extracting archive
  - Installing psr/simple-cache (1.0.1): Extracting archive
  - Installing illuminate/contracts (v8.83.27): Extracting archive
  - Installing spatie/laravel-package-tools (1.12.1): Extracting archive
  - Installing symfony/deprecation-contracts (v2.5.2): Extracting archive
  - Installing guzzlehttp/guzzle (7.8.0): Extracting archive
  - Installing spatie/laravel-google-fonts (1.2.3): Extracting archive
  - Installing squizlabs/php_codesniffer (3.7.1): Extracting archive

So it must be caused by the psr/container or the psr/simple-cache I’m guessing?
Because the error disappears after this?

Are you not able to require your dependencies all from the same place? Either move Acorn to your theme dependencies, or move your theme dependencies to your Bedrock dependencies

Otherwise you’re going to run into conflicts like this. That Spatie package is trying to install Laravel v10 packages because it isn’t aware that you’re already using Laravel v9 (via Acorn) since you’re installing your dependencies in two different places.

1 Like

Never really thought of that to be honest, gonna give that a go and see if that helps.
Thanks Ben!

Yeah that actually works perfectly, thanks!
Do you guys always add your theme dependencies to Bedrock anyway? Feels a bit wrong-ish to add theme specific packages to the wordpress dependencies?

Now that @Log1x updated his packages for Acorn 4.x to Support Laravel 10, I’ve run into the same issue.

I also never came to the idea to move theme-deps to Bedrock. But as @ben suggested I moved Acorn to the theme. Is there any possible downside for that?