Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to locate a class or view for component [fas-cloud] #6

Closed
nguyentranchung opened this issue Jul 5, 2020 · 28 comments · Fixed by #9
Closed

Unable to locate a class or view for component [fas-cloud] #6

nguyentranchung opened this issue Jul 5, 2020 · 28 comments · Fixed by #9

Comments

@nguyentranchung
Copy link

Description

I installed as instructed, but encountered an error

Facade\Ignition\Exceptions\ViewException
Unable to locate a class or view for component [fas-cloud].

Environment

  • PHP 7.4.7
  • Windows 10
@nguyentranchung
Copy link
Author

I debugged the result

image

fab-cloud not registered

I try edit code

        $this->callAfterResolving(Factory::class, function (Factory $factory) {
            $factory->add('fontawesome-brands', [
                'path' => __DIR__ . '/../resources/svg/brands',
                'prefix' => 'fab',
            ]);
            $factory->add('fontawesome-regular', [
                'path' => __DIR__ . '/../resources/svg/regular',
                'prefix' => 'far',
            ]);

            $factory->add('fontawesome-solid', [
                'path' => __DIR__ . '/../resources/svg/solid',
                'prefix' => 'fas',
            ]);


            $factory->registerComponents();
        });

See result:

image

@driesvints
Copy link
Contributor

Please share how you're using the icons.

@owenvoke
Copy link
Owner

owenvoke commented Jul 6, 2020

Hi @nguyentranchung, I haven't been able to replicate this issue. As @driesvints mentioned, could you share how you're using the icons?

I ran the following:

laravel new test && cd test
composer require owenvoke/blade-fontawesome

# add `{{ dd($this->compiler) }}` to `resources/views/welcome.blade.php`

Preview of resulting dd output

@nguyentranchung
Copy link
Author

@driesvints @owenvoke
I tried installing a new project so no problem happened.

But the current project has a problem, I don't understand where the problem is.
image

image

I tried to register in blade-icons.php config.

<?php

return [
    'sets' => [
        'default' => [
            'path' => 'resources/svg',
            'prefix' => 'icon',
            'class' => '',
        ],
        'fontawesome-brands' => [
            'path' => 'vendor/owenvoke/blade-fontawesome/resources/svg/brands',
            'prefix' => 'fab',
            'class' => 'icon',
        ],
        'fontawesome-regular' => [
            'path' => 'vendor/owenvoke/blade-fontawesome/resources/svg/regular',
            'prefix' => 'far',
            'class' => 'icon',
        ],
        'fontawesome-solid' => [
            'path' => 'vendor/owenvoke/blade-fontawesome/resources/svg/solid',
            'prefix' => 'fas',
            'class' => 'icon',
        ],
    ],
    'class' => '',
];

throw CannotRegisterIconSet
image

@driesvints
Copy link
Contributor

I tried to register in blade-icons.php config.

You don't need to do that. The package does that for you.

You still haven't shared how you're using the icons. Please share the code and tell us where and how it's being used.

@nguyentranchung
Copy link
Author

@driesvints
in TestController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Blade;

class TestController extends Controller
{
    /**
     * Handle the incoming request.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return \Illuminate\Http\Response
     */
    public function __invoke(Request $request)
    {
        dump(\Blade::debug());
        return view('test');
    }
}

test.blade.php

<x-fas-cloud />

That's it

@nguyentranchung
Copy link
Author

in vendor\owenvoke\blade-fontawesome\src\BladeFontAwesomeServiceProvider.php I add 1 line

<?php

declare(strict_types=1);

namespace OwenVoke\BladeFontAwesome;

use BladeUI\Icons\Factory;
use Illuminate\Support\ServiceProvider;

final class BladeFontAwesomeServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        $this->callAfterResolving(Factory::class, function (Factory $factory) {
            $factory->add('fontawesome-brands', [
                'path' => __DIR__ . '/../resources/svg/brands',
                'prefix' => 'fab',
            ]);

            $factory->add('fontawesome-regular', [
                'path' => __DIR__ . '/../resources/svg/regular',
                'prefix' => 'far',
            ]);

            $factory->add('fontawesome-solid', [
                'path' => __DIR__ . '/../resources/svg/solid',
                'prefix' => 'fas',
            ]);


            // ---------------------------------
            $factory->registerComponents();


        });

        if ($this->app->runningInConsole()) {
            $this->publishes([
                __DIR__ . '/../resources/svg' => public_path('vendor/blade-fontawesome'),
            ], 'blade-fontawesome');
        }
    }
}

image

It will be ok.

@owenvoke
Copy link
Owner

owenvoke commented Jul 7, 2020

That method is already called in the main package, so I don't see why it would need to be called again. 🤔 Any thoughts @driesvints?

@nguyentranchung
Copy link
Author

And then I comment out it, it's still ok.
Because cache views
image
image
image

@nguyentranchung
Copy link
Author

After call

php artisan view:clear

image

@nguyentranchung
Copy link
Author

This is my composer

{
"require": {
        "php": "^7.2.5",
        "artesaos/seotools": "^0.17.2",
        "calebporzio/sushi": "^2.0",
        "davejamesmiller/laravel-breadcrumbs": "^5.3",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^2.0",
        "glorand/laravel-model-settings": "^3.6",
        "guzzlehttp/guzzle": "^6.3",
        "jenssegers/agent": "^2.6",
        "kalnoy/nestedset": "^5.0",
        "kub-at/php-simple-html-dom-parser": "^1.9",
        "laracasts/flash": "^3.1",
        "laravel/framework": "^7.0",
        "laravel/scout": "^8.0",
        "laravel/socialite": "^4.4",
        "laravel/tinker": "^2.0",
        "nwidart/laravel-modules": "^7.1",
        "owenvoke/blade-fontawesome": "^1.1",
        "spatie/enum": "^2.3",
        "spatie/laravel-html": "^2.26",
        "spatie/laravel-medialibrary": "^7.19",
        "spatie/laravel-menu": "^3.5",
        "spatie/laravel-permission": "^3.13",
        "spatie/laravel-query-builder": "^2.8",
        "spatie/laravel-sitemap": "^5.7",
        "spatie/laravel-sluggable": "^2.2",
        "spatie/laravel-tags": "^2.6",
        "spatie/schema-org": "^2.14",
        "spatie/valuestore": "^1.2"
    },
    "require-dev": {
        "barryvdh/laravel-debugbar": "^3.3",
        "barryvdh/laravel-ide-helper": "^2.7",
        "beyondcode/laravel-query-detector": "^1.3",
        "facade/ignition": "^2.0",
        "fzaninotto/faker": "^1.9.1",
        "laravel/telescope": "^3.5",
        "laravel/ui": "^2.0",
        "mockery/mockery": "^1.3.1",
        "nunomaduro/collision": "^4.1",
        "phpunit/phpunit": "^8.5",
        "predis/predis": "^1.1"
    }
}

Is there any possibility of a conflict with another package?

@nguyentranchung
Copy link
Author

@driesvints @owenvoke

image

The problem occurs because provider BladeIconsServiceProvider runs before BladeFontAwesomeServiceProvider

@nguyentranchung
Copy link
Author

But in a completely new project, I got the opposite result

image

@nguyentranchung
Copy link
Author

@driesvints @owenvoke
I found the cause, this error will appear when you install the https://github.com/jeroennoten/Laravel-AdminLTE package.

@owenvoke
Copy link
Owner

owenvoke commented Jul 8, 2020

@nguyentranchung, thanks for your thorough debugging of this. 🤔

Just trying to create a reproducible repository for testing, but the almasaeed2010/adminlte package isn't downloading from dist or source. 😐

I've created a reproducible example in the following repository:
https://github.com/owenvoke/blade-fontawesome-adminlte-example


I'll have a look into this, not sure what would be causing this. 🤔 @driesvints, any thoughts? I haven't experienced this with any other packages I've used.

@driesvints
Copy link
Contributor

Erhm, can anyone walk me through what the adminlte package does and how it affects icons?

@nguyentranchung
Copy link
Author

@driesvints
Copy link
Contributor

driesvints commented Jul 9, 2020

I'm guessing this would probably be solved if we bound Illuminate\Contracts\View\Factory instead. Can anyone try replacing

    private function bootComponents(): void
    {
        $this->callAfterResolving('view', function ($view, Application $app) {
            $app->make(Factory::class)->registerComponents();
        });
    }

with

    private function bootComponents(): void
    {
        $this->callAfterResolving(\Illuminate\Contracts\View\Factory::class, function ($view, Application $app) {
            $app->make(Factory::class)->registerComponents();
        });
    }

locally instead to see if that solved the problem?

@owenvoke
Copy link
Owner

owenvoke commented Jul 9, 2020

@driesvints, just tested that and it doesn't seem to resolve the issue. 🤔

I'm assuming you were meaning to try changing that in the Blade Icons service provider?

@driesvints
Copy link
Contributor

yeah that's what I meant

@owenvoke
Copy link
Owner

owenvoke commented Jul 9, 2020

Yeah, it still throws the same error about the component not being found. 😬

@driesvints
Copy link
Contributor

I think I know where the problem lies. Can you try moving

    private function bootComponents(): void
    {
        $this->callAfterResolving(\Illuminate\Contracts\View\Factory::class, function ($view, Application $app) {
            $app->make(Factory::class)->registerComponents();
        });
    }

To the register method instead?

@owenvoke
Copy link
Owner

owenvoke commented Jul 9, 2020

I've moved it into the register method however it still seems to throw the error. 🤨 Apologies for taking up so much of your time.

@driesvints
Copy link
Contributor

No worries. I'll try it out myself when I find some free time. Appreciating any help until then.

@driesvints
Copy link
Contributor

I've found the issue. The problem is indeed boot of Admin LTE getting executed before boot of blade-fontawesome. All callAfterResolving belong in register actually. I didn't thought this through enough. I'll pr a fix and patch up blade-icons as well.

This was referenced Jul 9, 2020
@driesvints
Copy link
Contributor

Sent in #9 which solves this.

@ahmeddabak
Copy link

ahmeddabak commented Oct 4, 2020

Just upgraded my laravel installation to V8.x. i am getting the same error when running php artisan optimize, it happens when laravel tries to cache the views.

Unable to locate a class or view for component [fas-eye].

on \src\Illuminate\View\Compilers\ComponentTagCompiler.php:274

The wierd thing is that i do not get any errors when running php artisan view:cache on its own.

so i added

dd($this->aliases);

at vendor/laravel/framework/src/Illuminate/View/Compilers/ComponentTagCompiler.php:249

when i ran php artisan view:cache i get a long list of components, but when i ran php artisan optimize i only got

array:1 [
"dynamic-component" => "Illuminate\View\DynamicComponent"
]

I will try to find out what is happening, i am using:

blade-ui-kit/blade-icons 0.4.5
owenvoke/blade-fontawesome v1.5.0

@driesvints
Copy link
Contributor

@ahmeddabak we have the same issue on heroicons (and probably every blade icons library). I'm puzzled at what's causing this and appreciating any help.

blade-ui-kit/blade-heroicons#9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants