Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vite Server is running on 127.0.0.1 by default instead of localhost

Tags:

localhost

vite

Whenever i run npm run dev, i get vite running on domain 127.0.0.1 by default.

How to make vite run on localhost instead?

Theses are my configs:

package.json:

  "scripts": {
    "dev": "vite --host=localhost",
    "build": "vite build",
    "preview": "vite preview"
  },

vite.config.js:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    host: 'localhost',
    port: 3000
  }
})

vite console

like image 209
Darkpsinight_2 Avatar asked Nov 17 '25 03:11

Darkpsinight_2


1 Answers

This is intended. You can consult vite localhost behavior (read the note). To disable this behavior set dns.setDefaultResultOrder('verbatim') as explained there or upgrade Node.js to 17+. Also localhost

in your vite.config :

import { defineConfig } from 'vite'
import dns from 'dns'
import react from '@vitejs/plugin-react-swc'

dns.setDefaultResultOrder('verbatim')

export default defineConfig({
  plugins: [react()],
  server: {
    host: 'localhost',
    port: 3000
  }
})

Result:

vite console

Hope it answers to your question ! :)

like image 140
ArrayConstructor Avatar answered Nov 18 '25 19:11

ArrayConstructor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!