Member-only story
How to Fix the 404 Not Found Error for /livewire/livewire.js
If you’re encountering a 404 not found error for /livewire/livewire.js
, particularly on your production server, the root of the issue likely lies in your web server’s configuration for the specific site.
Understanding the 404 Not Found Error for /livewire/livewire.js
Livewire is designed to serve its own JavaScript files. By running the command php artisan route:list
, you should see a route associated with /livewire/livewire.js
:
GET|HEAD livewire/livewire.js ................................. Livewire\Mechanisms › FrontendAssets@returnJavaScriptAsFile
Typically, your web server won’t have issues with this setup. However, complications can arise if you’ve implemented custom headers for JavaScript files.
Here’s an example of a basic Nginx configuration:
location ~* \.(css|gif|ico|jpeg|jpg|js|png|svg|webp|woff2)$ {
expires 7d;
add_header Cache-Control "public, no-transform";
try_files $uri =404;
}
The issue occurs because this configuration causes Nginx to treat requests for /livewire/livewire.js
as static file requests, checking the filesystem to see if the file exists. Since Livewire serves this file dynamically, Nginx can't find it…