vitejs/vite · error · Error

HTTP server not available

Error message

HTTP server not available

What it means

After createServer resolves, the CLI checks that server.httpServer exists before calling server.listen(). If it is missing the dev server has no HTTP listener to bind, so the CLI throws 'HTTP server not available'. This guards against server middleware configurations that suppress the HTTP server (e.g. server.middlewareMode: true) being used with the `vite` serve command.

Solutions

  1. Remove server.middlewareMode: true from the config used by the `vite` CLI.
  2. If you need middleware mode, consume the server programmatically via createServer and skip server.listen().
  3. Use a separate config file (e.g. vite.ssr.config.ts) for middleware mode and the default for CLI dev.

Example fix

// before
export default defineConfig({ server: { middlewareMode: true } })
// after
export default defineConfig({ /* server.middlewareMode removed */ })
Defensive patterns

Strategy: validation

Validate before calling

function ensureHttpServerConfig(config) {
  if (config?.server?.middlewareMode) {
    return 'server.middlewareMode is incompatible with the vite dev CLI; consume the server programmatically instead.';
  }
  return null;
}

Type guard

function configSupportsListen(config) {
  return !config?.server?.middlewareMode;
}

Prevention

When it happens

Trigger: Running the `vite` (dev) CLI command while the config or inline options set server.middlewareMode: true, which skips creating an httpServer. Also possible if a plugin or custom server factory returns a server without httpServer.

Common situations: Reusing a middleware-mode config (meant for SSR integration with Express/Fastify) when starting vite standalone; copying an SSR example's vite.config into a fresh app.

Related errors


AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11). Data as JSON: /api/errors/d4dc4e8af67dd229. Report an issue: GitHub.

Appendix: source

Thrown at packages/vite/src/node/cli.ts:234

      const { createServer } = await import('./server')
      try {
        const server = await createServer({
          root,
          base: options.base,
          mode: options.mode,
          configFile: options.config,
          configLoader: options.configLoader,
          logLevel: options.logLevel,
          clearScreen: options.clearScreen,
          server: cleanGlobalCLIOptions(options),
          forceOptimizeDeps: options.force,
          experimental: {
            bundledDev: options.experimentalBundle,
          },
        })

        if (!server.httpServer) {
          throw new Error('HTTP server not available')
        }

        await server.listen()

        const info = server.config.logger.info

        const modeString =
          options.mode && options.mode !== 'development'
            ? `  ${colors.bgGreen(` ${colors.bold(options.mode)} `)}`
            : ''
        const viteStartTime = global.__vite_start_time ?? false
        const startupDurationString = viteStartTime
          ? colors.dim(
              `ready in ${colors.reset(
                colors.bold(Math.ceil(performance.now() - viteStartTime)),
              )} ms`,
            )
          : ''

View on GitHub (pinned to b4d66fee14)