vitest-dev/vitest · error
${error instanceof Error ? error.message : String(error)}
Error message
${error instanceof Error ? error.message : String(error)} What it means
Thrown from resolveConfig's catch when magicast cannot traverse the config AST. It reduces verbose magicast errors down to just the underlying error.message. Means the config's default export is not one of the recognized shapes (plain object, defineConfig call, mergeConfig call) and the traversal threw.
Solutions
- Read the captured message to identify the unparseable construct.
- Simplify the config default export to a literal object or a defineConfig/mergeConfig call.
- Move dynamic logic out of the default export (compute values into consts above it).
Example fix
// before
export default someCond ? { test: { ... } } : { test: { ... } }
// after
const config = { test: { coverage: { thresholds: { lines: 80 } } } }
export default defineConfig(config) Defensive patterns
Strategy: try-catch
Validate before calling
function configIsStaticallyParseable(defaultExport) {
// magicast-style heuristic: must be object, defineConfig(...), or mergeConfig(...)
return defaultExport?.$type === 'object'
|| (defaultExport?.$type === 'function-call'
&& ['defineConfig', 'mergeConfig'].includes(defaultExport.$callee))
} Try / catch
try {
await updateThresholds(...)
} catch (e) {
if (/magicast|config/i.test(e.message)) {
// simplify config default export, then retry
} else throw e
} Prevention
- Keep the config default export a literal object, defineConfig(...), or mergeConfig(...).
- Compute dynamic values into consts above the export, not inside it.
- Avoid ternaries and custom wrappers in the default export.
When it happens
Trigger: autoUpdate calling resolveConfig on a default export magicast cannot statically parse — dynamic spreads, computed keys, configs wrapped in helpers other than defineConfig/mergeConfig, or ternaries.
Common situations: Highly dynamic config files; configs built with custom helper functions; conditional exports; spread of external objects.
Related errors
- Unable to parse thresholds from configuration file
- Expected config.test.coverage.thresholds to be an object
- Failed to update coverage thresholds. Configuration file is…
- Missing configurationFile. The…
- Cannot parse ' ' because "module.stripTypeScriptTypes" is…
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/d73076eb59571ae9.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/node/coverage.ts:900
}
// "export default defineConfig(...)"
let config = resolveDefineConfig(mod)
if (config) {
return config
}
// "export default mergeConfig(..., defineConfig(...))"
if (mod.$type === 'function-call' && mod.$callee === 'mergeConfig') {
config = resolveMergeConfig(mod)
if (config) {
return config
}
}
}
catch (error) {
// Reduce magicast's verbose errors to readable ones
throw new Error(error instanceof Error ? error.message : String(error))
}
throw new Error(
'Failed to update coverage thresholds. Configuration file is too complex.',
)
}
function resolveDefineConfig(mod: any) {
if (mod.$type === 'function-call' && mod.$callee === 'defineConfig') {
// "export default defineConfig({ test: {...} })"
if (mod.$args[0].$type === 'object') {
return mod.$args[0]
}
if (mod.$args[0].$type === 'arrow-function-expression') {
if (mod.$args[0].$body.$type === 'object') {
// "export default defineConfig(() => ({ test: {...} }))"
return mod.$args[0].$bodyView on GitHub (pinned to 1fa9837ec2)