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
- Ensure the resolved config keeps at least environments.client (don't strip environments in config hooks).
- Inspect any plugin config hooks that return/merge environments and confirm they don't set environments to {}.
- 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
- Never return environments: {} from a plugin config hook.
- In multi-environment flows, prefer createBuilder and iterate environments explicitly.
- Add a smoke test asserting environments.client exists after resolveConfig.
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
- Environment "${name}" is not defined in the config.
- Required environments configuration were stripped out in the
- Invalid environment name "${name}". Environment names must o
- Either "build.lib.entry" or the top-level "input" option is
- rolldownOptions.input should not be an html file when buildi
AI-assisted analysis of vitejs/vite@89620f09af (2026-08-03).
Data as JSON: /data/errors/5962f86c1cad223f.json.
Report an issue: GitHub.