29

I want to expose my svelte app on LAN using the npm run dev --host command but it shows:

> frontend@0.0.1 dev
> svelte-kit dev


  SvelteKit v1.0.0-next.295

  local:   http://localhost:3000
  network: not exposed

  Use --host to expose server to other devices on this network


blest
  • 437
  • 1
  • 4
  • 10

4 Answers4

76

You have to add -- before the actual flag:

npm run dev -- --host

And it should output:

> project@0.0.1 dev
> svelte-kit dev "--host"


  SvelteKit v1.0.0-next.316

  local:   http://localhost:3000
  network: http://***.***.**.**:3000

  Note that all files in the following directories will be accessible to anyone on your network: src/lib, src/routes, .svelte-kit, src, node_modules
Odilf
  • 1,185
  • 7
  • 12
  • For homestead, have to look at Homestead.yaml and find the right ip. Then you go npm run dev -- --host={The IP From Homestead.yaml} – Apit John Ismail Oct 12 '22 at 08:15
  • 4
    You could improve this answer by explaining why you need to add '--' . For anyone else who arrives here - https://stackoverflow.com/questions/43046885/what-does-do-when-running-an-npm-command – codecowboy May 31 '23 at 15:51
5

If you use vite in the package.json file, do this on the dev line:

  "scripts": {
    "dev": "vite --host --port 8888",
   .....  what ever else was here.....
  },

if you use sirv, try this in the package.json :

    "start": "sirv public --no-clear --host 0.0.0.0",

If you want a different port try this:

    "start": "sirv public --no-clear --host 0.0.0.0 --port 8888",
shA.t
  • 16,580
  • 5
  • 54
  • 111
Strateger
  • 51
  • 1
  • 2
  • thanks for the help, Adding the line "vite --host --port 8888" in the package.json file actually did the trick for me. – damou_ 1 Aug 25 '23 at 06:21
1

In vite Two Methods as follows:

Method 1: Manually while running the app by typing this on the terminal

npm run dev -- --host

Method 2: Automatically By replacing the "dev" property line in package.json in the "scripts" object as follows:

"dev": "vite --host --port [PORT NO. YOU WANT TO USE]",

And when you run "npm run dev", it shows the network host address

0

You can add this to your vite.config.js

server: {
        host: true
      }