vite-plugin: Windows - Failed to load when loading vite dev server resources
- Laravel Vite Plugin Version: 0.2.3
- Laravel Version: 9.x-dev (to include vite changes)
- Node Version: 16.14.0
- NPM Version: 8.4.1
Description:
In Windows, when loading the resources from Vite it fails to load as 0.0.0.0 is an invalid address in Windows and doesn’t get rerouted to 127.0.0.1
Chrome’s output: Failed to load resource: net::ERR_ADDRESS_INVALID 0.0.0.0:5173/@vite/client:1
Manually going into the generated hot file and changing the url to http://localhost:5173
instead of http://0.0.0.0:5173
allows all the files to load.
Steps To Reproduce:
Set up Laravel Vite Plugin as outlined in the UPRADE.md on Windows I’m using Laravel Sail (with the 5173 port mapped) through WSL, although I don’t know if that makes a difference. Due to the line setting host: ‘0.0.0.0’,, even changing the host in the vite.config.js file doesn’t help as it gets overwritten by this plugin.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 23
- Comments: 60 (7 by maintainers)
Links to this issue
Commits related to this issue
- update vite to work with wsl2 see [this issue](https://github.com/laravel/vite-plugin/issues/28) — committed to ephbaum/twitter-clone by s0up9 2 years ago
- 🧑💻 Fixes `ERR_ADDRESS_INVALID` when using `npm run dev` This issue is documented [on GitHub](https://github.com/laravel/vite-plugin/issues/28) — committed to SturmB/botw-armor-upgrade-tracker by SturmB a year ago
I’m concerned about setting
localhost
in the hot file because on some machines this resolves to the IPv6 version (::1
) and Docker doesn’t always listen on IPv6.We could potentially set it to
127.0.0.1
to guarantee IPv4.However, forcing a local address in the hot file would make things even harder if wanted to get
sail share
working with the Vite dev server.There is maybe another option…
Vite allows you to configure where the client should look for the HMR server, using
server.hmr
. The Laravel Vite plugin should probably respect this, if set.Would you mind testing against this branch?
https://github.com/laravel/vite-plugin/tree/use-hmr-host-when-set
I think you’ll want to set this in your
vite.config.js
(leavingserver.host
unset):This worked for me:
@mariom9267 , did you try below?
Tested in Laravel 10 with Vite on default port. Add this section to
vite.config.js
Dear, I have a similar issue and am using Laravel Sail for my application. I attempted the suggested fixes, but my application is still running at host http://0.0.0.0:5173.
@shoeyn, @jessarcher, @pamitvn. I Found another simple but temporary solution, but it changed after your file changed 😭
Inside
public/hot
, change fromto
@RomanSarvarov in addition, can you try using the
--host
or--host 0.0.0.0
option when launching the Vite dev server?Guys, does this issue relate to my problem? I downloaded “use-hmr-host-when-set” branch files, then compile it by running
run npm run build
and then replacednode_modules\laravel-vite-plugin\dist
with compiled files.So then I run
npm run dev
inside my docker container and trying to fetch http://localhost:3000/@vite/client from my browser I have connection refused.My vite config:
My docker-compose.yml:
Windows WSL2.
I spent more than 5 hours solving this problem, but I cant 😦
Thanks so much for testing this @shoeyn! I’m glad we’ve found a way to support it!
I’ve opened a PR for the branch at https://github.com/laravel/vite-plugin/pull/42
We will continue to refine this as more feedback comes in. Ultimately I’d prefer if it “just worked” for you without a config option.
i think you have some wrong configuration as server key is not part of
laravel()
plugin you must take it afterplugins
key like thisThanks, it saved my day!!!
Hi @shoeyn,
As a first step, I have created https://github.com/laravel/vite-plugin/pull/30 that will allow you to customise the
server.host
value when running inside Sail.As noted above, you won’t be able to just set it to
localhost
because then the Vite server will only listen onlocalhost
inside the container.You would need to configure it in your
vite.config.js
something like this:or, a simpler, but potentially more fragile option:
Adding
worked for me. Thanks @jessarcher
I understand the suffering, but sometimes it is necessary to get used to new things, it is something that defines us as human beings. But try that from the file,
hot
worked for me in WSL2 on WindowsNot working on Laravel Sail (with the 5173 port mapped) through WSL.
vite.config.js:
docker-compose.yml:
Errors (running npm run dev inside container):
Not sure. My app_url is
http://localhost
and I have Connection Refused error, instead of 404 that I see in #40 issue.@jessarcher Works perfectly using that branch while setting the hmr host