Roots Discourse

Using "asset()->path()" results in "Undefined index: url"

Dev env:

  • Ubuntu 20.04
  • Trellis
  • Bedrock
  • Sage 10

Randomly it started to happen, project was working fine for very long time. It comes from using this:

# /var/www/html/web/app/themes/smart/app/setup.php
load_theme_textdomain('smart', asset('languages', 'smart')->path());

When the page loads, I get this error:

ErrorException thrown with message "Undefined index: url"

#20 ErrorException in /var/www/html/web/app/themes/smart/vendor/roots/acorn/src/Roots/Acorn/Assets/Manager.php:87
#19 Illuminate\Foundation\Bootstrap\HandleExceptions:handleError in /var/www/html/web/app/themes/smart/vendor/roots/acorn/src/Roots/Acorn/Assets/Manager.php:87
#18 Roots\Acorn\Assets\Manager:resolve in /var/www/html/web/app/themes/smart/vendor/roots/acorn/src/Roots/Acorn/Assets/Manager.php:66
#17 Roots\Acorn\Assets\Manager:manifest in /var/www/html/web/app/themes/smart/vendor/roots/acorn/src/Roots/Acorn/Assets/AssetsServiceProvider.php:22
#16 Roots\Acorn\Assets\AssetsServiceProvider:Roots\Acorn\Assets\{closure} in /var/www/html/web/app/themes/smart/vendor/illuminate/container/Container.php:873
#15 Illuminate\Container\Container:build in /var/www/html/web/app/themes/smart/vendor/illuminate/container/Container.php:758
#14 Illuminate\Container\Container:resolve in /var/www/html/web/app/themes/smart/vendor/roots/acorn/src/Illuminate/Foundation/Application.php:841
#13 Illuminate\Foundation\Application:resolve in /var/www/html/web/app/themes/smart/vendor/illuminate/container/Container.php:694
#12 Illuminate\Container\Container:make in /var/www/html/web/app/themes/smart/vendor/roots/acorn/src/Illuminate/Foundation/Application.php:826
#11 Illuminate\Foundation\Application:make in /var/www/html/web/app/themes/smart/vendor/roots/acorn/src/Roots/Acorn/Application.php:304
#10 Roots\Acorn\Application:make in /var/www/html/web/app/themes/smart/vendor/roots/acorn/src/helpers.php:42
#9 Roots\app in /var/www/html/web/app/themes/smart/vendor/roots/acorn/src/helpers.php:67
#8 Roots\asset in /var/www/html/web/app/themes/smart/app/setup.php:75
#7 Smart\{closure} in /var/www/html/web/wp/wp-includes/class-wp-hook.php:303
#6 WP_Hook:apply_filters in /var/www/html/web/wp/wp-includes/class-wp-hook.php:327
#5 WP_Hook:do_action in /var/www/html/web/wp/wp-includes/plugin.php:470
#4 do_action in /var/www/html/web/wp/wp-settings.php:556
#3 require_once in /var/www/html/web/wp-config.php:9
#2 require_once in /var/www/html/web/wp/wp-load.php:55
#1 require_once in /var/www/html/web/wp/wp-blog-header.php:13
#0 require in /var/www/html/web/index.php:6

…that refers to this:

# /var/www/html/web/app/themes/smart/vendor/roots/acorn/src/Roots/Acorn/Assets/Manager.php

     * Resolve the given manifest.
     * @param  string  $name
     * @return ManifestContract
     * @throws InvalidArgumentException
    protected function resolve(string $name, ?array $config): ManifestContract
        $config = $config ?? $this->getConfig($name);
        if (isset($config['handler'])) {
            return new $config['handler']($config);
        $url = $this->getMixHotUri($path = $config['path']) ?? $config['url'];
        $assets = isset($config['assets']) ? $this->getJsonManifest($config['assets']) : [];
        $bundles = isset($config['bundles']) ? $this->getJsonManifest($config['bundles']) : [];
        return new Manifest($path, $url, $assets, $bundles);

However on my laptop the same repo works just fine. Not even sure on how to troubleshoot it.

Any ideas?

In my experience, “this works in one environment but not another” is frequently due to a difference between case-sensitive/non-case-sensitive filesystems and something getting messed up there.

Failing that, I’d start by adding some code or a breakpoint to dump the value of $config inside resolve() to see if that sheds some light on what’s going on.

In my case both machines are Ubuntu 20.04, pretty much identical.

Dumping $config inside resolve() outputs the following:

# /var/www/html/web/app/themes/smart/vendor/roots/acorn/src/Roots/Acorn/Assets/

^ array:4 [▼
  "strategy" => "relative"
  "path" => "/var/www/html/web/app/themes/smart/public"
  "uri" => "http://smart.test/app/themes/smart/public"
  "manifest" => "/var/www/html/web/app/themes/smart/public/mix-manifest.json"

It seems that the Manager.php is looking for a key named url inside the $config array. Instead, the array has a key named uri. It seems like the behavior of the resolve() function has changed at some point?

In both systems I have "roots/acorn": "dev-main", in my composer.json. I believe it could have started to happen after composer update since the Acorn package seems to have a different contents in my host machines:

screenshot_1 (host_1) - everything still working

screenshot_2 (host_2) - has the issue

On both of my hosts, the Acorn package version seems to be 2.0.0 as seen from acorn.php (screenshot_1 and screenshot_2) but file structure and names are different.

From GitHub it seems that Acorn version 1.1.0 has the same file structure and file names as my host_1 (although version seems to be 2.0.0 according to acorn.php) that came from dev-main (composer.json), until some point - I suppose I haven’t run composer update at my host_1 for some time.

I uploaded both Acorn packages as zip to WeTransfer: WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free (link valid for 1 week) - if it’s helpful in any way. Btw I tested it by unpacked the Acorn package from my host_1 and the error disappeared.

It seems that the issue is related to a combination on factors one of witch is the way how the $config is genetared (I wasn’t able to figure that out yet). Other being the resolve() function in Roots\Acorn\Assets\Manager.

Someone with a good understanding Acorn might have some ideas?

This issue might be helpful:

Like you said, this is likely the cause. Since Acorn (and Sage 10) are still under development, I’d recommend pinning that to a specific commit rather than dev-main so you can rely on the code remaining the same.

1 Like

Good point, I totally forgot the fact that Sage 10 and Acorn are still under development.

Pinning to the last working commit helped me out since updating the assets config ( resulted in view composer not passing variables to views.

I got moving, thanks!

1 Like