Livewire 404: GET http://localhost/livewire/livewire.js net::ERR_ABORTED 404 (Not Found)
When you encounter a net::ERR_ABORTED 404 error specifically for the livewire.js file, the issue is rarely about your Blade templates or PHP logic. The code you providedâusing @livewireStyles, the component directive, and @livewireScriptsâis syntactically correct for a standard setup. The real culprit is almost always how Apache handles static assets relative to your document root.
The browser console error Uncaught ReferenceError: Livewire is not defined confirms that the JavaScript file never reached the client. When you see the URL http://localhost/livewire/livewire.js, it indicates that your application expects the asset at a path directly under the domain root, but Apache is looking for it in the wrong place relative to your project structure.
This mismatch happens because Livewire's development server (and sometimes production builds depending on configuration) serves the livewire.js and vendor directories from a specific location. If you are running this via PHP built-in server or a standard Apache setup where public_html points directly to your Laravel project root, the asset path resolution can become tricky if .htaccess rules aren't handling rewrites correctly for static assets.
To resolve the 404 without switching to a different environment immediately, you need to ensure that the route generating the asset tag is being processed correctly and that the file actually exists where Apache expects it.
First, verify your public directory structure. In a standard Laravel installation, all static assetsâCSS, JS, imagesâmust reside in the public folder. If your vendor directory (which contains Livewire's compiled files) is not symlinked or configured correctly to be accessible from public/vendor, the file won't load.
Run the following command in your project root to check if the asset exists:
ls -la public/vendor/livewire/livewire.js
If this path does not exist, the most common cause is that you haven't run the asset compilation step after installing the package via Composer. While Livewire attempts to serve assets on the fly during development, it often requires a specific setup if you are using Apache directly without the php artisan serve command, or if your .htaccess file is blocking access to certain paths.
However, there is a more likely scenario: The Asset Tag Generation. The error message shows GET http://localhost/livewire/livewire.js. This implies that the <script src="livewire.js"> tag (or its modern equivalent) is being generated pointing to a relative or absolute path that Apache interprets as /livewire/, rather than /public/livewire/ or the full URL.
In older versions of Livewire, or if using a non-standard installation, you might need to ensure that the public_path() helper is resolving correctly. But looking at your code:
@livewireStyles
// ...
@livewire("hello-world")
// ...
@livewireScripts
This should generate the correct script tags automatically. If the URL is missing the public segment (e.g., it's not http://localhost/public/livewire...), your Apache configuration might be rewriting requests meant for static files into your application routes, causing a 404 if no route matches /livewire.
Fixing the Apache Configuration
If you are running on Apache 2.4 as mentioned in your source material, ensure your .htaccess file in the public directory has standard Laravel rewrites:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Sometimes, strict security modules or specific Allow/Deny directives can block access to the /public/vendor/livewire/ directory. Ensure that your virtual host configuration allows access to the public folder and does not redirect requests for .js files unexpectedly.
The Modern Solution: Asset Compilation
The most robust fix, which aligns with current Livewire best practices, is to compile your assets so they serve a single bundled file rather than multiple chunks. This eliminates many pathing issues associated with browser caching and module loaders.
Run the following commands in your terminal:
php artisan vite
npm run build
After building, clear your config cache if you have been running the app in production mode recently:
php artisan config:clear
php artisan route:clear
Then, restart your Apache server. If you were previously using the PHP built-in server and switched to Apache, ensure that the public directory is correctly mapped as the document root in your httpd.conf or virtual host file.
Why This Happened
The 404 error occurs because the browser requests a resource at a path the web server cannot resolve to a physical file. In the context of Livewire, this usually stems from:
- Missing Compilation: The JS file doesn't exist in the expected location.
- Incorrect Document Root: Apache is looking for
/livewire/livewire.jsbut the file is actually at/public/vendor/livewire/livewire.js. - Rewrite Rule Conflict: A rewrite rule intercepts the request for
.jsfiles before reaching the static file handler.
By ensuring your assets are compiled and your Apache configuration respects the public directory boundaries, the livewire.js script will load correctly, resolving the ReferenceError: Livewire is not defined and allowing your component to bind data as intended. For further guidance on deployment configurations, resources like https://laravelcompany.com offer detailed articles on optimizing static asset delivery in production environments.