vitejs/vite · error · Error
config must export or return an object.
Error message
config must export or return an object.
What it means
In loadConfigFromFile (config.ts:2424-2428), after evaluating the config export (calling it if it's a function), Vite checks isObject(config). If the config file exports/returns a non-object (e.g. a string, number, array, or undefined), it throws because a Vite config must be a plain object.
Source
Thrown at packages/vite/src/node/config.ts:2428
try {
const { configExport, dependencies } = await (configLoader === 'bundle'
? bundleAndLoadConfigFile(
resolvedPath,
configRoot,
logLevel,
customLogger,
)
: configLoader === 'runner'
? runnerImportConfigFile(resolvedPath)
: nativeImportConfigFile(resolvedPath))
debug?.(`config file loaded in ${getTime()}`)
const config = await (typeof configExport === 'function'
? configExport(configEnv)
: configExport)
if (!isObject(config)) {
throw new Error(`config must export or return an object.`)
}
return {
path: normalizePath(resolvedPath),
config,
dependencies,
}
} catch (e) {
const logger = createLogger(logLevel, { customLogger })
checkBadCharactersInPath('The config path', 'file', resolvedPath, logger)
logger.error(colors.red(`failed to load config from ${resolvedPath}`), {
error: e,
})
throw e
}
}
async function nativeImportConfigFile(View on GitHub (pinned to 89620f09af)
Solutions
- Ensure the config file exports a plain object: export default { ... } (or defineConfig(() => ({ ... }))).
- If using a function form, make sure it returns an object, not an array or primitive.
- Verify the default export is actually reached (no early return / re-export of a non-config).
Example fix
// before
export default [reactPlugin]
// after
import { defineConfig } from 'vite'
export default defineConfig({ plugins: [reactPlugin] }) Defensive patterns
Strategy: type-guard
Validate before calling
import { isObject } from 'vite'
const cfg = typeof configExport === 'function' ? await configExport(env) : configExport
if (!isObject(cfg)) throw new Error('Config must export/return a plain object') Type guard
function isConfigObject(value: unknown): value is Record<string, any> {
return typeof value === 'object' && value !== null && !Array.isArray(value)
} Prevention
- Always export a plain object (or use defineConfig) from vite.config.
- If using a function config, ensure it returns an object, not an array or primitive.
- Lint the config file to confirm a valid default export.
When it happens
Trigger: A vite.config file whose default export or returned value is not an object — e.g. `export default 'vite'`, `export default 42`, a function that returns an array, or a file that exports nothing (undefined).
Common situations: Default export forgotten/typo'd; config file written as a list of plugins without wrapping in an object; a function config that returns the wrong shape; partial migration leaving an incomplete file.
Related errors
- `renderLegacyChunks` and `renderModernChunks` cannot be both
- Invalid environment name "${name}". Environment names must o
- `input` cannot contain glob characters. They are reserved, s
- Required environments configuration were stripped out in the
- The value passed to "base" option was malformed. It should b
AI-assisted analysis of vitejs/vite@89620f09af (2026-08-03).
Data as JSON: /data/errors/d9e701684f345306.json.
Report an issue: GitHub.