Registry / web-framework / vite-plugin-express

vite-plugin-express

JSON →
library1.0.3jsnpmunverified

A Vite plugin that integrates Express middleware into the Vite dev server for development mocking and API prototyping. Version 1.0.3 is the latest stable release, maintained via GitHub. It uses glob patterns to load server files automatically, supports hot reload without restarting Vite, and respects Vite's resolve aliases. Differs from alternatives like vite-plugin-mock by leveraging actual Express middleware, allowing realistic request/response handling including headers, CORS, and body parsing.

npm install vite-plugin-express
INSTALL
IMPORT
SIG · VITE-PLUGIN-EXPRES
V
vite-plugin-express
web-frameworkjavascriptv1.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

express
import express from 'vite-plugin-express'
const express = require('vite-plugin-express')
ESM-only; no CommonJS export.
express (default import)
import express from 'vite-plugin-express'
import { express } from 'vite-plugin-express'
The plugin is exported as default, not a named export.
vite config usage
import express from 'vite-plugin-express' export default defineConfig({ plugins: [express({...})] })
const express = require('vite-plugin-express')
Must be used in ESM config files.
Router export from server file
export default router
module.exports = router
Server files must export middleware as default (ESM) for plugin to detect.

Basic setup: Vite config with express plugin, and a server file exporting a default middleware router.

// vite.config.ts import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import express from 'vite-plugin-express'; export default defineConfig({ plugins: [ react(), express({ middlewareFiles: './server' }), ], resolve: { alias: { '@': './src', }, }, }); // server/account.ts import { Router } from 'express'; const router = Router(); router.get('/api/account', (request, response) => { response.status(200).send({ name: 'John Doe' }); }); export default router;
Debug
Known issues
breakingRequires Vite >=3.0.0. May not work with Vite 2.x.
fix
Upgrade Vite to >=3.0.0 or use an alternative plugin.
affects: <3.0.0
breakingESM-only: Import must use import statement, not require().
fix
Use ESM import syntax. If using CommonJS, consider dynamic import().
affects: >=1.0.0
gotchaServer files are loaded via glob. Files not matching the pattern will be ignored.
fix
Ensure middlewareFiles pattern matches all desired files (e.g., './server/**/*.ts').
affects: >=1.0.0
gotchaHot reload isolates Express server; changes to server files do not restart Vite.
fix
No action needed; changes apply on save.
affects: >=1.0.0
gotchaDefault middlewares include CORS and body parser. Overriding with defaultMiddlewares replaces them entirely.
fix
Provide a full array of middlewares if overriding; include cors and bodyParser.json if needed.
affects: >=1.0.0
Errors
Common errors & fixes
Error: require() of ES Module not supported
Using CommonJS require() to import the plugin.
fix
Switch to ESM by using import statement or set "type": "module" in package.json.
TypeError: express is not a function
Using named import { express } instead of default import.
fix
Use default import: import express from 'vite-plugin-express'
Cannot find module 'vite-plugin-express'
Plugin not installed or incorrect import path.
fix
Run npm install vite-plugin-express --save-dev and ensure import path is correct.
The requested module 'vite-plugin-express' does not provide an export named 'express'
Using named import when plugin only exports default.
fix
Use default import: import express from 'vite-plugin-express'
Error: Unexpected token 'export'
Server file using ESM exports but project is CommonJS.
fix
Convert project to ESM (type: module) or use dynamic import in server files.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
viterequiredPeer dependency required (>=3.0.0) for plugin API.
expressoptionalUsed in user code to create middleware; not a direct dependency but assumed.
globbyoptionalUsed internally for glob matching of middleware files.
Agent activity
31 hits · last 30 days
node
26
OpenAI (training)
1
Resources