vitejs/vite · error · Error
No environment found
Error message
No environment found
What it means
The top-level `build()` helper resolves the builder and takes the first environment via `Object.values(builder.environments)[0]`. If `builder.environments` is empty (no environment was created during config resolution), `environment` is undefined and `build()` throws 'No environment found'.
Solutions
- Ensure at least one environment is defined - typically keep the default `client` environment (do not set `environments: {}`).
- If you customize `environments`, include a valid entry like `environments: { client: { ... } }`.
- Check plugins/config functions that mutate `config.environments` to confirm they don't delete all entries.
Example fix
// before
export default defineConfig({ environments: {} })
// after
export default defineConfig({
environments: { client: { build: { outDir: 'dist/client' } } },
}) Defensive patterns
Strategy: validation
Validate before calling
import { resolveConfig } from 'vite'
async function assertHasEnvironment(cfg: any) {
const resolved = await resolveConfig(cfg, 'build', 'production', 'production')
if (Object.keys(resolved.environments || {}).length === 0) {
throw new Error('No environment found - define at least one (e.g. environments.client)')
}
} Type guard
function hasAtLeastOneEnvironment(envs: Record<string, unknown>): boolean {
return Object.keys(envs || {}).length > 0
} Prevention
- Never set environments: {} - keep at least the default client environment.
- Review plugins that mutate config.environments to ensure they don't empty it.
When it happens
Trigger: Calling `vite build` (or the programmatic `build()`) with a config that produces zero environments - e.g. an empty/filtered `environments` map, or a config that disables both default `client` and `ssr` environments.
Common situations: Setting `environments: {}` explicitly. Filtering out all environments via a plugin/config. Misconfigured `builder`/shared config that drops the default `client` environment. Experimental environment config that yields no entries.
Related errors
- Invalid environment name
- Either "build.lib.entry" or the top-level "input" option is…
- Environment " " is not defined in the config.
- `renderLegacyChunks` and `renderModernChunks` cannot be…
- rolldownOptions.input should not be an html file when…
AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11).
Data as JSON: /api/errors/5962f86c1cad223f.
Report an issue: GitHub.
Appendix: 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 b4d66fee14)