Laravel Blade says it cannot find a class or view for a component
Unable to locate a class or view for component [alert].Short answer
Blade finds your own components only in app/View/Components and resources/views/components. If the tag x-name has no matching class or view there, it fails. Check the file name against the kebab-case tag, use a dot for each subfolder, and register package components yourself with Blade::component or Blade::componentNamespace.
Fix it fast
1Find out which cause you have
List the places Blade auto-discovers components in, and look for the one named in the error.
ls app/View/Components find resources/views/components -name "*.blade.php"2Match what you see, then jump to its fix
- 1
The component tag is x-alert but no Alert class and no components/alert.blade.php existThe class or view is not in a discovered folder, or its name does not match the tagFix - 2
The file is app/View/Components/Forms/Input.php, and the tag is x-inputThe component sits in a subfolder, but the tag does not use dotsFix - 3
The class exists, but not under app/View/ComponentsThe component comes from a package or another folder and was never registeredFix
- 1
What does the error look like?
Unable to locate a class or view for component [alert].InvalidArgumentException: Unable to locate a class or view for component
Cause 1 of 3
The class or view is not in a discovered folder, or its name does not match the tag
1Check
Class components are auto-discovered under app/View/Components and their views under resources/views/components. Tags use the kebab-case form of the class name, so Alert is x-alert.
ls app/View/Components resources/views/components2Fix
Create the component with Artisan so both files land in the right place, or move your files there.
php artisan make:component Alert
# anonymous, view only:
php artisan make:component alert --view3Verify
Render the tag in a view, for example <x-alert />, and reload the page.
ls app/View/Components/Alert.php resources/views/components/alert.blade.phpConfirmed by laravel.com
Cause 2 of 3
The component sits in a subfolder, but the tag does not use dots
1Check
For a component nested deeper, the tag uses a dot for each folder level.
find app/View/Components resources/views/components -mindepth 22Fix
Write the tag with the folder path, for example x-forms.input.
<x-forms.input />3Verify
Reload the page that used the tag.
ls resources/views/components/forms/input.blade.phpConfirmed by laravel.com
Cause 3 of 3
The component comes from a package or another folder and was never registered
1Check
Only the two default folders are discovered. A package must register its components in its service provider.
grep -rn "Blade::component" app/ vendor/<vendor>/<package>/src 2>/dev/null2Fix
Register one component by name, or a whole namespace by convention.
// service provider boot()
Blade::component('package-alert', AlertComponent::class);
// or a whole namespace, used as <x-nightshade::calendar />
Blade::componentNamespace('Nightshade\\Views\\Components', 'nightshade');3Verify
Use the registered tag in a view.
<x-package-alert />Confirmed by laravel.com
How do I stop it coming back?
- Create components with php artisan make:component rather than by hand, so both files are placed correctly.
- Keep one folder level per dot in the tag, and keep file names in line with the kebab-case tag.
- Register package components in the package's service provider.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix