livewire: Problem loading Livewire.js
It’s likely to be a simple thing but I can’t manage to solve it on my own smh.
On my local env it’s working fine just doing this:
...
@livewireAssets
</body>
This of course load the file properly as it should. Now, after I deployed the site (using Forge) it didn’t load the file at all with the relative path. My network tab (Chrome) says:
Failed to load resource: the server responded with a status of 404 (Not Found) (index):14 Uncaught ReferenceError: Livewire is not defined at (index):14
I though it might be the directory/file that isn’t accesible but when I hit that path adding the IP at the beginning it loads the js file just fine (http://165.227.80.80/livewire/livewire.js?)id=8456629107e9ab1c518f)
So, then checking the docs I saw that you can customized the base_url initializing the directive with a custom url, so I tried that also:
@livewireAssets(['base_url' => ENV('APP_URL'));
But even with the full path the file isn’t loading:

This is the link to the site.
Has anyone faced this problem before?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 48 (9 by maintainers)
Commits related to this issue
- Fix liverwire issue in production https://github.com/livewire/livewire/issues/242 — committed to ceithir/sakkaku by ceithir 3 years ago
I had the same problem, in v1.0.12, again deploying to a DigitalOcean server (initially setup via Laravel Forge).
I resolved it by publishing the assets:
php artisan vendor:publish --force --tag=livewire:assets(See also: #241)
The
@livewireScriptsblade directive is still required, but it automatically correctly fetches the assets from/public/vendor/livewire/livewire.jsI suspect there’s something in
livewire.jswhich when executed upon load returns the 404 error, and it depends or relies on its origin URL. This would explain why fetching the URL in the browser as per OP issue (but not executing it) is successful.Hello everyone … may i join in and post a solution no one has thought of yet.
I was experiencing this issue “livewire.js - 404 not found” too … on the NGINX server. The same app worked fine in an apache2 environment. The same app also worked fine when nginx is acting as reverse proxy and just passing the data to apache2.
So i figured the issue is not any setting in the app - it is NGINX related. And it makes absolut sense. NGINX is a very performant web server (among other things) … this is because (next to many other reason) static files are not passed on to the php interpreter, they are served and cached directly.
What is happening with livewire (unless the assets are published and actually existing on the server, so nginx can serve them) is that the livewire.js file is build/served by the laravel app … this means PHP. But in the default nginx server configuration the request never gets that far, nginx just does not find the static js file and returns the 404 … never passing the request to the laravel app.
Cutting a long story short … there is 2 solutions to fix this issue:
1.) publish the livewire.js file any any other static file, so nginx can return them.
2.) Add one line of code to the nginx config to tell nginx to check if the static file can be found on the disk/cache if not send the request to php-fpm (in our case the index.php file) so it can be build dynamically.
Here is the code … usually you may already have a directive in your nginx config that tells nginx what to do with static files … just add this line within the directive:
try_files $uri /index.php?$query_string;So a complete directive added to the nginx server config may look like this:
if you only want this behavior for js files create a new directive and get js off the list in the previous example.
Voila … thats it and the solution to the issue that many experienced. This nginx configuration “fix” will also deal with other files that have the same issue.
Cheers WebBoty
'asset_url' => url('/'),this also work and it is much nicer then the above .I just ran into this error myself.
This must have something to do with the way that my Nginx is configured (using Forge). If I use the same route, but drop the
.jsfile extension I always get a status 200 back. But the file extension does some weird things with Nginx for me.Anyway, publishing the assets worked 👍
Same here with Livewire 2.2.2, only on production server (non forge managed) with nginx. Publishing assets fixed it.
And then adding:
at the end of the post-autoload-dump composer hook as specified by the docs > Publishing Frontend Assets.
#241 should fix this.
This works for me, but causes a error when run
composer update. I solve this using'asset_url' => '../..',Solucione esto en Laravel 8 en el archivo config/livewire.php en esta linea tienes que especificar la dirección de tu aplicación para que pueda cargar correctamente el @livewireScripts
'asset_url' => null,The main cause of this is that Livewire is reading form the localhost’s URL which is pre-defined by livewire. (Not sure why they decided to do that.) You can change this by:
Let me know if this solves your issue.
i use this in my config/livewire.php file & and it perfectly works for me.
'asset_url' => "http://localhost/live_wire_1/public",by the way , that ‘live_wire_1’ is my project name. use ur project name there. /sparklefirst step: you should run php artisan vendor:publish --force --tag=livewire:assets After that, you should run your project through $php artisan serve
I stumbled over this problem while I installed Laravel 8 with livewire. I put “@php artisan vendor:publish --force --tag=livewire:assets” in my composer.json in the ‘post-update-cmd’ script. Then it worked. But it feels not like a good solution. How to do this the right way?
First of all, sorry for taking ages to reply to all of you. I did solve the issue at the time with the custom
asset_url. But, for Livewire v3 this option has been removed from the config. So, I faced the issue while upgrading one of my projects.The issue is related with Nginx, so adding an additional block to properly parse the call to the js file solved the issue. For a more detailed explanation, you can check this blog post (thanks @benjamincrozat). Pretty much:
So, right before the location block that sets your custom headers, add this one, which will prevent Nginx from interfering with this specific location:
I am using
I can’t say exactly what from what version I upgraded, but here is my reply on another thread: https://github.com/livewire/livewire/issues/2338#issuecomment-776689991
It’s not resolving the @livewire on my production I don’t know why, but on the local machine it’s working fine
If it’s a new install and you have not published your assets before, try clearing all caches… php artisan optimize
Worked for me too… I don’t know why, but seems like a bug.