{"record":{"id":"027b786ffa498f31","repo":"vitejs/vite","slug":"config-was-resolved-for-a-build-expected-a-ser","errorCode":null,"errorMessage":"Config was resolved for a \"build\", expected a \"serve\" command.","messagePattern":"Config was resolved for a \"build\", expected a \"serve\" command\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/server/index.ts","lineNumber":509,"sourceCode":"    previousShortcutsState?: ShortcutsState<ViteDevServer>\n    previousRestartPromise?: Promise<void> | null\n    previousForceOptimizeOnRestart?: boolean\n  },\n): Promise<ViteDevServer> {\n  // The dev server is a long-running, interactive process whose outputs\n  // (network responses, HMR updates) cannot be replayed from a cache.\n  disableCache()\n\n  const config = isResolvedConfig(inlineConfig)\n    ? inlineConfig\n    : await resolveConfig(inlineConfig, 'serve')\n\n  if (usedConfigs.has(config)) {\n    throw new Error(`There is already a server associated with the config.`)\n  }\n\n  if (config.command !== 'serve') {\n    throw new Error(\n      `Config was resolved for a \"build\", expected a \"serve\" command.`,\n    )\n  }\n\n  usedConfigs.add(config)\n\n  const initPublicFilesPromise = initPublicFiles(config)\n\n  const { root, server: serverConfig } = config\n  const httpsOptions = await resolveHttpsConfig(config.server.https)\n  const { middlewareMode } = serverConfig\n\n  const resolvedOutDirs = getResolvedOutDirs(\n    config.root,\n    config.build.outDir,\n    config.build.rolldownOptions.output,\n  )\n  const emptyOutDir = resolveEmptyOutDir(","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/server/index.ts#L491-L527","documentation":"Thrown by the dev server factory when the passed ResolvedConfig has config.command === 'build' instead of 'serve'. A dev server requires a config resolved in serve mode because command affects how plugins, options, and optimizations are applied.","triggerScenarios":"Passing a config produced by resolveConfig(inlineConfig, 'build') (or build(...) internals) to createServer(). The check at server/index.ts:508 verifies config.command === 'serve'.","commonSituations":"Reusing a build config object for a dev server in a unified pipeline. Holding a ResolvedConfig from a build and accidentally feeding it to createServer on restart. Custom scripts that resolve config once and branch on command but pass the wrong object.","solutions":["Let createServer resolve the config itself: call createServer(inlineConfig) with the raw InlineConfig, not a pre-resolved build config.","If you must pre-resolve, use resolveConfig(inlineConfig, 'serve') for the dev server path.","Do not share one ResolvedConfig between build and serve — resolve twice with the correct command."],"exampleFix":"// before\nconst config = await resolveConfig(cfg, 'build')\nawait createServer(config) // throws\n// after\nawait createServer(cfg)            // let Vite resolve for serve\n// or:\nconst serveConfig = await resolveConfig(cfg, 'serve')\nawait createServer(serveConfig)","handlingStrategy":"validation","validationCode":"if (isResolvedConfig(inlineConfig) && inlineConfig.command !== 'serve') {\n  throw new Error('Pass an InlineConfig or resolve with serve')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Let createServer resolve the config itself by passing InlineConfig.","Always pair resolveConfig(inlineConfig, 'serve') with createServer and 'build' with build()."],"tags":["dev-server","configuration","command-mismatch"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}