vitejs/vite · error · Error

Environment " " is not defined in the config.

Error message

Environment "${name}" is not defined in the config.

What it means

DevEnvironment's constructor looks up config.environments[name]; if there is no entry for the requested name, it throws. Every DevEnvironment must correspond to a resolved environment in the config (default 'client' and 'ssr' are auto-created).

Solutions

  1. Declare the environment under the 'environments' key in vite.config before constructing it.
  2. Verify the name string matches exactly (case-sensitive) between config and constructor.
  3. Use the default 'client'/'ssr' unless you intentionally add custom environments.
  4. If the environment was removed intentionally, also remove the code that constructs it.

Example fix

// before
new DevEnvironment('rte', config, context) // 'rte' not in config
// after — vite.config.ts
environments: { rte: { ... } }
// then
new DevEnvironment('rte', config, context)
Defensive patterns

Strategy: validation

Validate before calling

function assertEnvironmentDeclared(config, name) {
  if (!(name in (config.environments ?? {}))) {
    throw new Error(`Declare environments.${name} in vite.config before constructing it`)
  }
}
assertEnvironmentDeclared(config, name)

Type guard

function isDeclaredEnvironment(config, name): boolean {
  return Object.prototype.hasOwnProperty.call(config.environments ?? {}, name)
}

Prevention

When it happens

Trigger: Constructing a DevEnvironment with a name not present in resolved config.environments — e.g. instantiating a custom RTE/worker environment before declaring it under the 'environments' key, or a typo in the name.

Common situations: Custom integrations creating environments dynamically, framework adapters that pass a name mismatched to config, or removing an environment from config while code still references it.

Related errors


AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11). Data as JSON: /api/errors/ecaa92703d2d8ca3. Report an issue: GitHub.

Appendix: source

Thrown at packages/vite/src/node/server/environment.ts:120

  /**
   * Hot channel for this environment. If not provided or disabled,
   * it will be a noop channel that does nothing.
   *
   * @example
   * environment.hot.send({ type: 'full-reload' })
   */
  hot: NormalizedHotChannel

  public bundledDev?: BundledDev

  constructor(
    name: string,
    config: ResolvedConfig,
    context: DevEnvironmentContext,
  ) {
    let options = config.environments[name]
    if (!options) {
      throw new Error(`Environment "${name}" is not defined in the config.`)
    }
    if (context.options) {
      options = mergeConfig(
        options,
        context.options,
      ) as ResolvedEnvironmentOptions
    }
    super(name, config, options)
    if (
      options.isBundled ||
      (name === 'client' && config.experimental.bundledDev)
    ) {
      context.disableDepsOptimizer = true
      this.bundledDev = new BundledDev(this)
    }

    this._pendingRequests = new Map()

View on GitHub (pinned to b4d66fee14)