{"record":{"id":"5962f86c1cad223f","repo":"vitejs/vite","slug":"no-environment-found","errorCode":null,"errorMessage":"No environment found","messagePattern":"No environment found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/build.ts","lineNumber":574,"sourceCode":"            ssrManifestPlugin(),\n            buildReporterPlugin(config),\n          ]\n        : []),\n      nativeLoadFallbackPlugin(),\n    ],\n  }\n}\n\n/**\n * Bundles a single environment for production.\n * Returns a Promise containing the build result.\n */\nexport async function build(\n  inlineConfig: InlineConfig = {},\n): Promise<RolldownOutput | RolldownOutput[] | RolldownWatcher> {\n  const builder = await createBuilder(inlineConfig, true)\n  const environment = Object.values(builder.environments)[0]\n  if (!environment) throw new Error('No environment found')\n  return builder.build(environment)\n}\n\nfunction resolveConfigToBuild(\n  inlineConfig: InlineConfig = {},\n  patchConfig?: (config: ResolvedConfig) => void,\n  patchPlugins?: (resolvedPlugins: Plugin[]) => void,\n): Promise<ResolvedConfig> {\n  return resolveConfig(\n    inlineConfig,\n    'build',\n    'production',\n    'production',\n    false,\n    patchConfig,\n    patchPlugins,\n  )\n}","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/build.ts#L556-L592","documentation":"The top-level `build()` helper resolves the builder and takes the first environment via `Object.values(builder.environments)[0]`. If `builder.environments` is empty (no environment was created during config resolution), `environment` is undefined and `build()` throws 'No environment found'.","triggerScenarios":"Calling `vite build` (or the programmatic `build()`) with a config that produces zero environments - e.g. an empty/filtered `environments` map, or a config that disables both default `client` and `ssr` environments.","commonSituations":"Setting `environments: {}` explicitly. Filtering out all environments via a plugin/config. Misconfigured `builder`/shared config that drops the default `client` environment. Experimental environment config that yields no entries.","solutions":["Ensure at least one environment is defined - typically keep the default `client` environment (do not set `environments: {}`).","If you customize `environments`, include a valid entry like `environments: { client: { ... } }`.","Check plugins/config functions that mutate `config.environments` to confirm they don't delete all entries."],"exampleFix":"// before\nexport default defineConfig({ environments: {} })\n// after\nexport default defineConfig({\n  environments: { client: { build: { outDir: 'dist/client' } } },\n})","handlingStrategy":"validation","validationCode":"import { resolveConfig } from 'vite'\nasync function assertHasEnvironment(cfg: any) {\n  const resolved = await resolveConfig(cfg, 'build', 'production', 'production')\n  if (Object.keys(resolved.environments || {}).length === 0) {\n    throw new Error('No environment found - define at least one (e.g. environments.client)')\n  }\n}","typeGuard":"function hasAtLeastOneEnvironment(envs: Record<string, unknown>): boolean {\n  return Object.keys(envs || {}).length > 0\n}","tryCatchPattern":null,"preventionTips":["Never set environments: {} - keep at least the default client environment.","Review plugins that mutate config.environments to ensure they don't empty it."],"tags":["environments","build","config-validation","vite-6"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}