Running svelte dev on server

10,326

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"

Share:
10,326
Dara Java
Author by

Dara Java

Updated on July 21, 2022

Comments

  • Dara Java
    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
    Dara Java over 3 years
    Can you just tell me how you figured that out?
  • Madacol
    Madacol over 3 years
    I thought svelte used sirv in the back, so I googled how to do it for sirv. 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
    David Roth about 2 years
    While I LOVE Svelte, its little things like this that makes it so frustrating!
  • domi
    domi about 2 years
    They 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
    Eric almost 2 years
    -H is the same.