{"id":"8a5168decb9c4147","repo":"vitejs/vite","slug":"environment-name-is-not-defined-in-the-config","errorCode":null,"errorMessage":"Environment \"${name}\" is not defined in the config.","messagePattern":"Environment \"(.+?)\" is not defined in the config\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/build.ts","lineNumber":1751,"sourceCode":"export const toOutputFilePathInCss: typeof toOutputFilePathWithoutRuntime =\n  toOutputFilePathWithoutRuntime\nexport const toOutputFilePathInHtml: typeof toOutputFilePathWithoutRuntime =\n  toOutputFilePathWithoutRuntime\n\nexport class BuildEnvironment extends BaseEnvironment {\n  mode = 'build' as const\n\n  isBuilt = false\n  constructor(\n    name: string,\n    config: ResolvedConfig,\n    setup?: {\n      options?: EnvironmentOptions\n    },\n  ) {\n    let options = config.environments[name]\n    if (!options) {\n      throw new Error(`Environment \"${name}\" is not defined in the config.`)\n    }\n    if (setup?.options) {\n      options = mergeConfig(\n        options,\n        setup.options,\n      ) as ResolvedEnvironmentOptions\n    }\n    super(name, config, options)\n  }\n\n  async init(): Promise<void> {\n    if (this._initiated) {\n      return\n    }\n    this._initiated = true\n  }\n}\n","sourceCodeStart":1733,"sourceCodeEnd":1769,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/build.ts#L1733-L1769","documentation":"In the BuildEnvironment constructor (build.ts:1749-1752), Vite looks up config.environments[name]; if that environment isn't defined in the resolved config it throws. Build environments must be declared in the config's environments map before they can be built.","triggerScenarios":"Constructing a BuildEnvironment (or triggering a build for one) with a name that has no entry under config.environments — e.g. building environment 'ssr' when only 'client' is configured, or a typo'd name.","commonSituations":"Adding a custom environment name in build tooling without declaring it in vite.config environments; renaming an environment in one place but not the config; referencing an SSR environment that was disabled.","solutions":["Declare the environment in config.environments, e.g. environments: { ssr: { ... } }.","Match the environment name used in build tooling exactly to a key in environments.","If the environment was removed intentionally, stop referencing it in build scripts."],"exampleFix":"// before\nenvironments: { client: { ... } }\n// build code references 'ssr'\n// after\nenvironments: { client: { ... }, ssr: { ... } }","handlingStrategy":"validation","validationCode":"const resolved = await resolveConfig(config, 'build')\nconst names = Object.keys(resolved.environments)\nif (!names.includes(targetName)) {\n  throw new Error(`Environment '${targetName}' not in config; available: ${names.join(', ')}`)\n}","typeGuard":"function environmentIsDefined(config: ResolvedConfig, name: string): boolean {\n  return name in config.environments\n}","tryCatchPattern":null,"preventionTips":["Declare every environment you build under config.environments.","Keep environment names consistent between config and build scripts.","When removing an environment, grep build tooling for stale references."],"tags":["build","environment","config"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}