kit: Endless reloading by start svelte-kit it with VS Code Remote-SSH terminal
Describe the bug
Endless reloading by start it from VS Code Remote-SSH terminal:
npm run dev -- --open
(open localhost:3000
on local computer and svelte is running on remote)
Termorary solution:
With --host
it works great:
npm run dev -- --host --open
(open 111.222.333.444:3000
(server ip) on local computer and svelte is running on remote)
Other projects works fine on the same server with same VS Code Remote-SSH, sapper-template
, for example. Problem (for me) only with SvelteKit now.
Logs Please include browser console and server logs around the time this bug occurred.
To Reproduce
- Open VS Code
- Install Remote-SSH (if it doesn’t exist)
- Connect to you remote server with Remote-SSH
pnpm init svelte@next my-app
pnpm i
npm run dev -- --open
Expected behavior Work on VS Code Remote-SSH with port forwarding without endless reloading.
Stacktraces
If you have a stack trace to include, we recommend putting inside a <details>
block for the sake of the thread’s readability:
Stack trace
[vite] connecting...
content.js:1 Uncaught (in promise) Error: Unexpected token u in JSON at position 0
at A (content.js:1)
A @ content.js:1
Promise.then (async)
(anonymous) @ content.js:1
(anonymous) @ content.js:1
t @ content.js:1
(anonymous) @ content.js:1
(anonymous) @ content.js:1
client:184 WebSocket connection to 'ws://localhost:24678/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
(anonymous) @ client:184
client:340 [vite] server connection lost. polling for restart...
(index):1 Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: http://localhost:3001/src/routes/index.svelte?import
start.js:1024 Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: http://localhost:3001/src/routes/$layout.svelte?import
async function (async)
start @ start.js:1018
(anonymous) @ (index):222
Information about your SvelteKit Installation:
Diagnostics
-
The output of
npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite --binaries --browsers
System: OS: Linux 4.15 Ubuntu 18.04.4 LTS (Bionic Beaver) CPU: (2) x64 Intel Xeon E3-12xx v2 (Ivy Bridge, IBRS) Memory: 98.10 MB / 984.89 MB Container: Yes Shell: 4.4.20 - /bin/bash
Binaries: Node: 14.16.1 - /usr/local/bin/node Yarn: 2.0.0-rc.27 - ~/.npm-global/bin/yarn npm: 6.13.7 - ~/.npm-global/bin/npm
npmPackages: @sveltejs/kit: next => 1.0.0-next.80 svelte: ^3.29.0 => 3.37.0
-
Your browser
Chrome 88.0.4324.150 (Official), (64 bit)
Severity
Not critical, but it is incrase REPL from 1 second to 8 seconds 😦
if i use the solution with adding --host
as additional parameter.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 14
- Comments: 47 (11 by maintainers)
Commits related to this issue
- upgrade svelte's deps, fix endless reload[^1] [^1]: https://github.com/sveltejs/kit/issues/1134#issuecomment-947922754 — committed to tacone/loki by tacone 3 years ago
- upgrade svelte's deps, fix endless reload[^1] [^1]: https://github.com/sveltejs/kit/issues/1134#issuecomment-947922754 — committed to tacone/loki by tacone 3 years ago
Thank you very much for your help! 😊
I got it working 🥳 I have following setup on my local machine:
If you have a similar setup, here is what you need to do:
1. Adjust your nginx.conf
Make sure to adjust the paths to your certificate and private key file. If you want to create a self-signed certificate for local testing, you can use this command:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.crt
Don’t forget to reload your config after you have done the changes:
sudo nginx -s reload
2. Adjust your svelte.config.js
Just restart SvelteKit and you are good to go:
npm run dev -- --open
From now on you should only use https://localhost, because http://localhost:3000 won’t work with HMR.
*Thanks again everyone for your help ❤️
I think
next.169
broke something in relation to this. When I upgraded tonext.169
this afternoon, the websocket could not be reached anymore and the page would endlessly reload. I reverted back tonext.164
and everything is working again as intended.Here are my svelte config file and docker compose file. Again, this works with
next.164
but does not work withnext.169
:svelte.config.js
docker-compose.yml
I just want to inform that this is still happening on @sveltejs/kit@1.0.0-next.96
And opening port 24678 is working as a workaround
Hi everyone,
Mostly leaving this for future readers, but I believe I have found a fix for people using sveltekit behind a TLS reverse proxy, with no local/native TLS in sveltekit it self.
If you were previously running a config setting protocol, host, etc, you must strip the config down to just this:
This fixed the issue for me, and sveltekit no longer loops infinitely. It seems like you no longer have to specify the host, local port, or protocol.
My setup:
I hope this helps!
I made some tests on “@sveltejs/kit”: “1.0.0-next.169/170”/ “@sveltejs/adapter-node”: “1.0.0-next.49”.
response for ws://localhost:3001/ using “@sveltejs/kit”: “1.0.0-next.168”/ “@sveltejs/adapter-node”: “1.0.0-next.48”. It’s working correctly.
Response for ws://localhost:3001/ using “@sveltejs/kit”: “1.0.0-next.170”/ “@sveltejs/adapter-node”: “1.0.0-next.49”. The browser reloading after this request.
The browser always reload after it try to access ws://localhost:3001/ using svelte.kt 169 or 170. Using 168 it don’t reload.
My frontend container is behind haproxy with self sign certificate. Only the port 3001 is open for vite without certificate.
I’m not accessing via SSH but via normal browser.
What was changed in Vite/Svelte from 168 to 169 version?
Thank you for the help.
Using Devilbox - Docker remote environment, it works with this simple config, running
npm run dev -- --https --host 0.0.0.0
and going to https://app.loc:3000 instead of just https://app.loc (there I get a 403). Also for the generated cert from Vite for localhost an exception has to be allowed once.What confused me was that SvelteKit did work just fine with HMR under https://app.loc/ without having a port number in the URL in the past. So a change in the way HRM is done must/could have been introduced in Vite or SvelteKit.
Being able to tell Vite to use the cert from https://app.loc instead of making a new one for localhost on start could possibly fix this issue. There is an option for vite.server.hmr.server where I assume this could be solved however the option does not seem to work with a self signed cert so far.
I’m having this issue using WSL2 and Nginx as a reverse proxy with https and custom domain (http://localhost:3000 -> https://svltkt.local).
Opening the ports and using
--host
as suggested above works for host IP but not custom domain added the C:\Windows\System32\drivers\etc\hosts. Any suggestions?Ahh, finally. The endless reload has taken a break.
pnpm dev -- --open
on@sveltejs/kit 1.0.0-next.301
and asvelte.config.js
with:local:
Windows 8.1 VS Code Remote client,remote:
Slackware 15 (headless), Node 16 (Remote, as in 7000 Km 😄 )I have been able to get rid of this issue and keep HMR when running through Docker Compose in WSL2 behind Traefik with the following setup:
docker-compose.dev.yml
client/Dockerfile
client/package.json
client/svelte.config.js
The site is then available on
http://localhost
.@YugoCode
I’m running nginx and the svelte app in Docker.
svelte config:
Dockerfile for svelte app:
Container config (docker-compose):
This was a bug I fixed (at least mostly) in Vite 2.9, so I’m not sure we necessarily need an FAQ as it wasn’t really user confusion, but a bug
Okay, finally I found the trick.
So I don’t even know how it works before version next
169
… But if you use a reverse proxy and/or containers to run SvelteKit The ports it should be same (in my case at least) with the SvelteKit running port. In my case in the docker it’s run on theport 3000
, and map to3001
host port and i have a reverse proxy in front of it, and runs onport 80
and pass to3001
.This config solved the problem for me. (http)
Got the same error using traefik + https with mkcert.
After many tests and configurations, this solved the endless reload:
Ref.: https://github.com/vitejs/vite/issues/1653#issuecomment-816188959
Just to mention: I had the same problem with a custom domain. As soon as I tried to invoke the application with a custom domain, it started reloading the page every 2-5 seconds. HMR-port was open as stated above, no ports were blocked by some firewall, it even happened when I started it locally with
pnpm dev
(having the--host
-switch as well).What helped in my case was the plugin
vite-plugin-host
, which explicitly mentions to enable a custom domain in dev as well. Once imported and configured in thesvelte.config.js
, also the custom domain worked fine.working example of nginx vhost via wsl2
@JBusillo I’m on 1.0.0-next.114. Still doesn’t work for custom domains (
<http:https>://svltkt.local
).<http:https>://localhost:3000
works as expected.@GreenRobot777 – Are you opening up both your application port (default: 3000) and the websocket port (default 24678) on your remote server? This has been suggested as a “workaround” – which really is a misstatement. It’s absolutely necessary to manually open those ports, as the browser client (running on the local server) needs to connect to those ports to support HMR. SvelteKit can’t alter your system’s firewall settings. This necessity applies to Docker containers, too. I’ve tested it on my local and remote servers with the default HMR port (24678) and again with an override (3334).
You also need to specify
--host
, otherwise it will only accept connections from your remote server’s localhost, not from your “external” local server.For me, I changed svelte.config.js as described above, then executed commands 1 through 5 in your Reproduction instructions, then:
If you just want to use the default ports, omit changing your svelte.config.js, and run:
I hope I understood your issue correctly. Please let me know. If this does resolve your issue,
it probably can be closedthe remedy for this issue would be clarification in the documentation. (FAQ?)Opening port 24678 on the server and forwarding it in VSCode resolved the issue for me and enabled auto-reload. I use it with remote development with VSCode in Docker containers.
You want to see something like this in the Chrome console:
This error in the console says there is something wrong with the Vite connection:
Some background information
SvelteKit uses Vite for its hot module reload (HMR) feature. This uses a WebSocket that uses a different port than the one opened with Sveltekit (default 24678, but it is configurable, but the configuration seems to not apply with SvelteKit). When you fire up SvelteKit using
npm run dev
it starts the server and creates a Vite WebSocket that listens to connections.Related topics