{"id":"d4dc4e8af67dd229","repo":"vitejs/vite","slug":"http-server-not-available","errorCode":null,"errorMessage":"HTTP server not available","messagePattern":"HTTP server not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/vite/src/node/cli.ts","lineNumber":234,"sourceCode":"      const { createServer } = await import('./server')\n      try {\n        const server = await createServer({\n          root,\n          base: options.base,\n          mode: options.mode,\n          configFile: options.config,\n          configLoader: options.configLoader,\n          logLevel: options.logLevel,\n          clearScreen: options.clearScreen,\n          server: cleanGlobalCLIOptions(options),\n          forceOptimizeDeps: options.force,\n          experimental: {\n            bundledDev: options.experimentalBundle,\n          },\n        })\n\n        if (!server.httpServer) {\n          throw new Error('HTTP server not available')\n        }\n\n        await server.listen()\n\n        const info = server.config.logger.info\n\n        const modeString =\n          options.mode && options.mode !== 'development'\n            ? `  ${colors.bgGreen(` ${colors.bold(options.mode)} `)}`\n            : ''\n        const viteStartTime = global.__vite_start_time ?? false\n        const startupDurationString = viteStartTime\n          ? colors.dim(\n              `ready in ${colors.reset(\n                colors.bold(Math.ceil(performance.now() - viteStartTime)),\n              )} ms`,\n            )\n          : ''","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/cli.ts#L216-L252","documentation":"In the CLI serve action (cli.ts:233-234), after createServer() returns, Vite checks server.httpServer. If it is null/undefined (the underlying Node HTTP server was not created), it throws 'HTTP server not available'. This happens when server configuration disables or prevents the HTTP server from being instantiated.","triggerScenarios":"Running `vite` (serve/dev) with a config that sets server options incompatible with creating an HTTP server, or a middleware/plugin that returns a server without an httpServer — e.g. misusing server.middlewareMode or a custom server factory.","commonSituations":"Configuring the dev server in middleware mode (where no httpServer is attached) but still running via the CLI `vite` command; a plugin that overrides server creation; port/host conflicts causing a non-standard server object.","solutions":["Avoid server.middlewareMode (or { server: { middlewareMode: true } }) when launching via the `vite` CLI, since middleware mode has no httpServer.","If you need a custom server, use the JS API (createServer + server.listen) and handle the no-httpServer case yourself rather than the CLI.","Remove any plugin/config that strips or replaces the httpServer."],"exampleFix":"// before\nexport default { server: { middlewareMode: true } } // then run `vite`\n// after\nexport default {} // let the CLI create a normal HTTP server\n// (or use the JS API: const server = await createServer({ server: { middlewareMode: true } }))","handlingStrategy":"validation","validationCode":"const server = await createServer(config)\nif (!server.httpServer) {\n  throw new Error('Dev server has no httpServer — avoid middlewareMode via the CLI')\n}","typeGuard":"function hasHttpServer(server: ViteDevServer): boolean {\n  return server.httpServer != null\n}","tryCatchPattern":null,"preventionTips":["Don't enable server.middlewareMode when launching through the `vite` CLI.","Use the JS API (createServer) directly when you need middleware mode.","Avoid plugins that replace the underlying HTTP server."],"tags":["dev-server","cli","http","config"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}