{"record":{"id":"5ecd59e0e5d73dca","repo":"vitejs/vite","slug":"required-environments-configuration-were-stripped","errorCode":null,"errorMessage":"Required environments configuration were stripped out in the config hook","messagePattern":"Required environments configuration were stripped out in the config hook","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/config.ts","lineNumber":1664,"sourceCode":"          external: config.ssr?.external,\n          noExternal: config.ssr?.noExternal,\n        },\n      } satisfies EnvironmentOptions,\n      {\n        resolve: configEnvironmentsSsr.resolve ?? {},\n      },\n    ).resolve\n  }\n\n  if (config.build?.ssrEmitAssets !== undefined) {\n    configEnvironmentsSsr ??= {}\n    configEnvironmentsSsr.build ??= {}\n    configEnvironmentsSsr.build.emitAssets = config.build.ssrEmitAssets\n  }\n\n  // The client and ssr environment configs can't be removed by the user in the config hook\n  if (!config.environments.client || (!config.environments.ssr && !isBuild)) {\n    throw new Error(\n      'Required environments configuration were stripped out in the config hook',\n    )\n  }\n\n  // Merge default environment config values\n  const defaultEnvironmentOptions = getDefaultEnvironmentOptions(config)\n  // Some top level options only apply to the client environment\n  const defaultClientEnvironmentOptions: UserConfig = {\n    ...defaultEnvironmentOptions,\n    input: config.input,\n    resolve: config.resolve, // inherit everything including mainFields and conditions\n    optimizeDeps: config.optimizeDeps,\n  }\n  const defaultNonClientEnvironmentOptions: UserConfig = {\n    ...defaultEnvironmentOptions,\n    dev: {\n      ...defaultEnvironmentOptions.dev,\n      createEnvironment: undefined,","sourceCodeStart":1646,"sourceCodeEnd":1682,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/config.ts#L1646-L1682","documentation":"Vite guarantees that a resolved config always carries environments.client and (for non-build/serve flows) environments.ssr. After user plugins run the config hook, the resolver checks these still exist; if a plugin deleted them the build is unsafe, so it throws. This is a safety net against misbehaving plugins.","triggerScenarios":"A plugin's config or configResolved hook returns a config object without environments.client (or environments.ssr in serve mode), effectively stripping the default environments. Also triggered by plugins that replace config.environments wholesale with an object missing those keys.","commonSituations":"Plugin authors who return { environments: { ...customOnly } } from the config hook, accidentally omitting client/ssr; custom environment-management plugins that mis-handle the defaults.","solutions":["Fix the offending plugin to merge rather than replace config.environments.","Ensure the config hook returns { environments: { client: { ... }, ssr: { ... }, ...yours } }.","Update or remove plugins that mutate environments incompatibly."],"exampleFix":"// before (plugin config hook)\nconfig: () => ({ environments: { worker: { ... } } }) // strips client/ssr\n// after\nconfig: (cfg) => ({ environments: { ...cfg.environments, worker: { ... } } })","handlingStrategy":"validation","validationCode":"function validateEnvironmentsIntact(newConfig, oldConfig) {\n  const required = ['client'];\n  return required.filter((k) => !newConfig?.environments?.[k]);\n}","typeGuard":"function configHasRequiredEnvironments(config, isBuild) {\n  return Boolean(config?.environments?.client && (isBuild || config.environments.ssr));\n}","tryCatchPattern":null,"preventionTips":["Merge into config.environments in plugin hooks, never replace it.","Test plugins that mutate environments against a real build."],"tags":["config","environments","plugins"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}