{"id":20656,"library":"vite-express","title":"vite-express","description":"Vite integration for Express servers, enabling seamless full-stack development with HMR, static file serving, and client-side routing support. Current stable version: 0.22.1 (as of mid-2024). Maintained with monthly releases. Key differentiators: minimal boilerplate, automatic Vite middleware injection, and simple listen/bind API. Alternatives like vite-plugin-node or @danielwii/vite-plugin-express require more manual configuration. Ships TypeScript types.","status":"active","version":"0.22.1","language":"javascript","source_language":"en","source_url":"https://github.com/szymmis/vite-express","tags":["javascript","express","vite","integration","module","connector","typescript"],"install":[{"cmd":"npm install vite-express","lang":"bash","label":"npm"},{"cmd":"yarn add vite-express","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-express","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; Express server is required for integration.","package":"express","optional":false},{"reason":"peer dependency; Vite dev server and build tooling are required.","package":"vite","optional":false}],"imports":[{"note":"Default export; ESM-only since v0.10.0. CommonJS require is not supported.","wrong":"const ViteExpress = require('vite-express')","symbol":"ViteExpress","correct":"import ViteExpress from 'vite-express'"},{"note":"Default export, not named. Do not destructure.","wrong":"import { ViteExpress } from 'vite-express'","symbol":"ViteExpress","correct":"import ViteExpress from 'vite-express'"},{"note":"TypeScript types are included. The listen() method accepts an Express app instance, not a factory.","wrong":"import ViteExpress from 'vite-express'; ViteExpress.listen(express(), 3000);","symbol":"ViteExpress (with TypeScript)","correct":"import ViteExpress from 'vite-express'; const app = express(); ViteExpress.listen(app, 3000);"},{"note":"Parameter order: app first, server second. Common mistake.","wrong":"ViteExpress.bind(server, app);","symbol":"ViteExpress.bind","correct":"import ViteExpress from 'vite-express'; const server = app.listen(3000); ViteExpress.bind(app, server);"}],"quickstart":{"code":"import express from 'express';\nimport ViteExpress from 'vite-express';\n\nconst app = express();\n\napp.get('/api/hello', (req, res) => {\n  res.json({ message: 'Hello from Express!' });\n});\n\n// In development, Vite server is started automatically.\n// In production, static files are served.\nViteExpress.listen(app, 3000, () => {\n  console.log('Server listening on port 3000');\n});","lang":"typescript","description":"Basic Express server with a single API route, integrated with ViteExpress for development HMR and production static serving."},"warnings":[{"fix":"Update imports: `import ViteExpress from 'vite-express'` instead of `import { viteExpress } from 'vite-express'`.","message":"Default export changed from an object to a function in v0.10.0","severity":"breaking","affected_versions":"<0.10.0"},{"fix":"Use `ViteExpress.listen(app, 3000).then(() => console.log('listening'))` or pass a callback to `app.listen` and use `ViteExpress.bind()`.","message":".listen() no longer accepts a callback as third argument in v0.15.0; use .then() instead","severity":"breaking","affected_versions":">=0.15.0 <0.16.0"},{"fix":"Remove ViteExpress.config() calls; use Vite's own defineConfig.","message":"ViteExpress.config() is deprecated since v0.12.0; import { defineConfig } from 'vite' instead","severity":"deprecated","affected_versions":">=0.12.0"},{"fix":"Use ViteExpress.bind() after manually creating the server with https.createServer().","message":"ViteExpress.listen() does not work with HTTPS servers created via express.createServer()","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Set build.outDir in vite.config.js to 'dist' (default). If changed, use ViteExpress.listen() with options: `{ buildDir: 'your-custom-dir' }`.","message":"In production, ViteExpress automatically serves the built files from 'dist/' folder. Ensure Vite build output is in the correct directory.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Set `\"moduleResolution\": \"bundler\"` in tsconfig.json for compatibility with Vite's ESM-only packages.","message":"When using TypeScript, ensure tsconfig.json includes 'moduleResolution': 'node' or 'bundler' to resolve Vite's ESM exports.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure you pass a valid Express app: `const app = express(); ViteExpress.listen(app, 3000);`","cause":"Calling ViteExpress.listen() without an Express app instance.","error":"TypeError: Cannot read properties of undefined (reading 'use')"},{"fix":"Remove the callback argument and use `.then()`: `ViteExpress.listen(app, 3000).then(() => console.log('listening'));`","cause":"Using callback syntax with ViteExpress.listen() in v0.15.0+.","error":"Error: listen() callback is not supported. Use .then() instead."},{"fix":"Run `npm install vite-express` and ensure package.json has `\"type\": \"module\"` or use .mjs extension.","cause":"vite-express not installed or ESM import not configured.","error":"Module not found: Can't resolve 'vite-express'"},{"fix":"Switch to ESM import syntax: `import ViteExpress from 'vite-express';`","cause":"Using CommonJS require() to import vite-express.","error":"ERR_REQUIRE_ESM: require() of ES Module not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}