vitejs/vite · critical · Error

No environment found

Error message

No environment found

What it means

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.

Source

Thrown at packages/vite/src/node/build.ts:574

            ssrManifestPlugin(),
            buildReporterPlugin(config),
          ]
        : []),
      nativeLoadFallbackPlugin(),
    ],
  }
}

/**
 * Bundles a single environment for production.
 * Returns a Promise containing the build result.
 */
export async function build(
  inlineConfig: InlineConfig = {},
): Promise<RolldownOutput | RolldownOutput[] | RolldownWatcher> {
  const builder = await createBuilder(inlineConfig, true)
  const environment = Object.values(builder.environments)[0]
  if (!environment) throw new Error('No environment found')
  return builder.build(environment)
}

function resolveConfigToBuild(
  inlineConfig: InlineConfig = {},
  patchConfig?: (config: ResolvedConfig) => void,
  patchPlugins?: (resolvedPlugins: Plugin[]) => void,
): Promise<ResolvedConfig> {
  return resolveConfig(
    inlineConfig,
    'build',
    'production',
    'production',
    false,
    patchConfig,
    patchPlugins,
  )
}

View on GitHub (pinned to 89620f09af)

Solutions

  1. Ensure the resolved config keeps at least environments.client (don't strip environments in config hooks).
  2. Inspect any plugin config hooks that return/merge environments and confirm they don't set environments to {}.
  3. For multi-environment control use createBuilder() and iterate builder.environments instead of the single-env build().

Example fix

// before (plugin config hook stripping environments)
config() { return { environments: {} } }
// after
config() { return {} }
Defensive patterns

Strategy: validation

Validate before calling

const builder = await createBuilder(config, true)
const envs = Object.values(builder.environments)
if (envs.length === 0) {
  throw new Error('No environments resolved — check that config/plugins keep environments.client')
}

Type guard

function hasBuildableEnvironment(builder: ViteBuilder): boolean {
  return Object.keys(builder.environments).length > 0
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of vitejs/vite@89620f09af (2026-08-03). Data as JSON: /data/errors/5962f86c1cad223f.json. Report an issue: GitHub.