{"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":"critical","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/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/build.ts#L556-L592","documentation":"The top-level build() helper (build.ts:569) resolves the builder, then takes the first environment via Object.values(builder.environments)[0]. If the builder has zero environments it throws 'No environment found', because there is nothing to bundle.","triggerScenarios":"Calling build(inlineConfig) where the resolved config's environments object is empty — e.g. a plugin's config hook deleted environments, or config was mutated to remove the default 'client' environment.","commonSituations":"A plugin's config() hook returns a partial config that accidentally clears environments; an environments: {} override; a misconfigured custom builder that drops the client/ssr defaults.","solutions":["Ensure the resolved config keeps at least environments.client (don't strip environments in config hooks).","Inspect any plugin config hooks that return/merge environments and confirm they don't set environments to {}.","For multi-environment control use createBuilder() and iterate builder.environments instead of the single-env build()."],"exampleFix":"// before (plugin config hook stripping environments)\nconfig() { return { environments: {} } }\n// after\nconfig() { return {} }","handlingStrategy":"validation","validationCode":"const builder = await createBuilder(config, true)\nconst envs = Object.values(builder.environments)\nif (envs.length === 0) {\n  throw new Error('No environments resolved — check that config/plugins keep environments.client')\n}","typeGuard":"function hasBuildableEnvironment(builder: ViteBuilder): boolean {\n  return Object.keys(builder.environments).length > 0\n}","tryCatchPattern":null,"preventionTips":["Never return environments: {} from a plugin config hook.","In multi-environment flows, prefer createBuilder and iterate environments explicitly.","Add a smoke test asserting environments.client exists after resolveConfig."],"tags":["build","environment","config","plugin"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}