Running svelte dev on server
Solution 1
Declare the environment variable HOST=0.0.0.0
HOST=0.0.0.0 npm run dev
inspiration / possible source: https://github.com/lukeed/sirv/issues/29#issuecomment-497907602
You can also modify the dev
script in the package.json
and prepend HOST=0.0.0.0
"scripts": {
"build": "rollup -c",
"dev": "HOST=0.0.0.0 rollup -c -w",
"start": "sirv public"
},
And now you can simply run npm run dev
Solution 2
Actually, the message:
Your application is ready~!
- Local: http://localhost:5000
- Network: Add `--host` to expose
is telling you to put --host
in sirv public
instead of rollup -c -w
which is a bit of a confusing message.
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public --host"
},
Solution 3
Just add the bold part to package.json
"start": "sirv public --host 0.0.0.0"
Dara Java
Updated on July 21, 2022Comments
-
Dara Java almost 2 years
I am running svelte like this on my server:
$ npm run dev Your application is ready~! 🚀 - Local: http://localhost:5000 ────────────────── LOGS ──────────────────
Which is great. However, when I try to access through my public ip, the bundle is not found. I.E. When I type
<publicIP>:5000
into the browser. It doesn't show up. The port is open and accessible. Is there any way to achieve this?The request just fails. But shouldn't it work if it's running on localhost:5000? I have set up a node server and I can indeed access it on port 5000, but it doesn't serve the files properly like
npm run dev
does. -
Dara Java over 3 yearsCan you just tell me how you figured that out?
-
Madacol over 3 yearsI thought svelte used
sirv
in the back, so I googled how to do it forsirv
. I'm still not sure it really uses sirv, it might just be a lucky standard, that's why the possible source is there -
David Roth about 2 yearsWhile I LOVE Svelte, its little things like this that makes it so frustrating!
-
domi about 2 yearsThey should add a link to @Treedbox's answer in that message that OP quoted. I tried a whole lot of stuff before discovering this, and now it works.
-
Eric almost 2 years
-H
is the same.