{"id":"ecaa92703d2d8ca3","repo":"vitejs/vite","slug":"environment-name-is-not-defined-in-the-config-ecaa92","errorCode":null,"errorMessage":"Environment \"${name}\" is not defined in the config.","messagePattern":"Environment \"(.+?)\" is not defined in the config\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/server/environment.ts","lineNumber":120,"sourceCode":"  /**\n   * Hot channel for this environment. If not provided or disabled,\n   * it will be a noop channel that does nothing.\n   *\n   * @example\n   * environment.hot.send({ type: 'full-reload' })\n   */\n  hot: NormalizedHotChannel\n\n  public bundledDev?: BundledDev\n\n  constructor(\n    name: string,\n    config: ResolvedConfig,\n    context: DevEnvironmentContext,\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 (context.options) {\n      options = mergeConfig(\n        options,\n        context.options,\n      ) as ResolvedEnvironmentOptions\n    }\n    super(name, config, options)\n    if (\n      options.isBundled ||\n      (name === 'client' && config.experimental.bundledDev)\n    ) {\n      context.disableDepsOptimizer = true\n      this.bundledDev = new BundledDev(this)\n    }\n\n    this._pendingRequests = new Map()\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/server/environment.ts#L102-L138","documentation":"The DevEnvironment constructor at packages/vite/src/node/server/environment.ts:120 looks up config.environments[name]; if that key is absent it throws. Every environment created via new DevEnvironment(name, ...) must have a matching entry resolved from the user's config.environments (client and ssr are seeded by default).","triggerScenarios":"Constructing a DevEnvironment with an arbitrary name that was not declared in config.environments; a plugin spawning an environment named 'worker' without declaring environments.worker; renaming an environment in only one place; accessing server.environments.foo that was never configured.","commonSituations":"Custom plugin creating environments dynamically; migrating to the environments API without declaring every environment used; typo in an environment name between config and consumer code.","solutions":["Declare the environment in config.environments (e.g. environments: { myEnv: {} }) before constructing/using it.","Fix the typo so the name passed to DevEnvironment matches an existing key.","If you only need default client/ssr, use server.environments.client or server.environments.ssr instead of inventing a name."],"exampleFix":"// before\nconst env = new DevEnvironment('rsc', config, ctx)\n// config has no environments.rsc\n\n// after\nexport default defineConfig({\n  environments: { rsc: { /* options */ } },\n})","handlingStrategy":"validation","validationCode":"function assertEnvironmentDeclared(name: string, environments: Record<string, unknown>) {\n  if (!(name in environments)) {\n    throw new Error(`Environment \"${name}\" must be declared in config.environments`)\n  }\n}","typeGuard":"function isDeclaredEnvironment(name: string, environments: Record<string, unknown>): boolean {\n  return Object.prototype.hasOwnProperty.call(environments, name)\n}","tryCatchPattern":null,"preventionTips":["Declare every environment name in config.environments before constructing DevEnvironment instances.","Reuse server.environments.client / .ssr rather than inventing names.","Validate environment names in a config plugin to catch typos at load time."],"tags":["environment","config","dev-server"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}