Looking for: http://localhost:5173/?
Use our interactive tools to check port conflicts and generate framework-specific commands:
lsof -i :5173 (Mac/Linux)netstat -ano | findstr :5173 (Windows)
npm run dev -- --port 5174vite --port 5174
npm run dev -- --hostvite --host 0.0.0.0
npm run buildnpm run preview (preview build)
Essential vite.config.js configurations for development:
// vite.config.js
export default defineConfig({
server: {
port: 5173,
open: true,
cors: true
}
})
server: {
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true
}
}
}
Running Vite applications in Docker containers:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 5173
CMD ["npm", "run", "dev", "--", "--host"]
FROM node:18-alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
Port 5173 is commonly used by:
This error occurs when another application is already using port 5173. Solutions:
npm run dev -- --port 5174export default defineConfig({
server: {
port: 5174
}
})
netstat -ano | findstr :5173 then taskkill /PID [PID] /F
lsof -i :5173 then kill -9 [PID]
If changes aren't automatically reflecting in the browser:
By default, Vite's development server only listens on localhost:
npm run dev -- --host
export default defineConfig({
server: {
host: '0.0.0.0'
}
})
http://YOUR_IP:5173
When Vite can't find your modules or imports fail:
rm -rf node_modules && npm installWhen production builds fail or take too long:
npm run type-checknpm run build -- --analyzenpm install @vitejs/plugin-vueEnable Vue SFC support and HMR
npm install @vitejs/plugin-reactFast refresh and JSX support
npm install typescript @types/nodeBuilt-in TypeScript compilation
// .env files
VITE_API_URL=http://localhost:3000
VITE_APP_TITLE=My AppAccess with import.meta.env.VITE_*
const Component = lazy(() => import('./Component'))vite-bundle-analyzer to visualize bundle sizenpm install sass less stylusBuilt-in support, just import .scss/.less files
// postcss.config.js
export default {
plugins: [require('autoprefixer')]
}
css: {
preprocessorOptions: {
stylus: {
additionalData: '@import "./src/vars.styl"'
}
}
}
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'~': path.resolve(__dirname, './src')
}
}
node --versionnpm list viterm -rf node_modules/.viteserver: { https: true } for testing HTTPSnpm audit regularly--mode production for production buildsbuild: { sourcemap: false }