vitest-dev/vitest · error
Unable to parse thresholds from configuration file
Error message
Unable to parse thresholds from configuration file: ${message} What it means
Wrapper thrown by assertConfigurationModule when reading thresholds from the config file fails for any reason. It catches the inner TypeError (248) or any property-access exception and re-throws with a readable 'Unable to parse thresholds from configuration file' prefix, embedding the underlying message. Indicates the config module's shape does not match the expected {test:{coverage:{thresholds}}} structure.
Solutions
- Read the embedded ${message} to find the exact cause (it carries the inner error text).
- Fix the config so config.test.coverage.thresholds resolves to an object.
- Validate the config loads standalone (e.g. import it directly) before enabling autoUpdate.
Example fix
// before
export default { plugins: [] } // no `test` key
// after
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: { coverage: { thresholds: { lines: 80 } } }
}) Defensive patterns
Strategy: try-catch
Validate before calling
async function canParseThresholds(configFilePath) {
try {
const mod = await import(configFilePath)
return mod?.default?.test?.coverage?.thresholds != null
} catch { return false }
} Try / catch
try {
await vitest.reportCoverage(coverage, true) // triggers autoUpdate
} catch (e) {
if (/Unable to parse thresholds/.test(e.message)) {
// read inner message, fix config.test.coverage.thresholds, retry
} else throw e
} Prevention
- Validate that the config module exports { test: { coverage: { thresholds } } } before autoUpdate.
- Import the config standalone to confirm it loads without error.
- Surface the embedded inner message when reporting this error.
When it happens
Trigger: autoUpdate parsing a config where accessing config.test.coverage.thresholds throws — e.g. config is null/undefined, test is missing, or coverage is null, so the chained access throws and is caught here.
Common situations: Config file exporting something other than a Vitest config object; corrupted or partial config; thresholds referenced before being defined.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- ${error instanceof Error ? error.message : String(error)}
- 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/ec9c2d9eccb496cc.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/node/coverage.ts:869
}
}
function assertConfigurationModule(config: unknown): asserts config is {
test: {
coverage: { thresholds: NonNullable<CoverageOptions['thresholds']> }
}
} {
try {
// @ts-expect-error -- Intentional unsafe null pointer check as wrapped in try-catch
if (typeof config.test.coverage.thresholds !== 'object') {
throw new TypeError(
'Expected config.test.coverage.thresholds to be an object',
)
}
}
catch (error) {
const message = error instanceof Error ? error.message : String(error)
throw new Error(
`Unable to parse thresholds from configuration file: ${message}`,
)
}
}
function resolveConfig(configModule: any) {
const mod = configModule.exports.default
try {
// Check for "export default { test: {...} }"
if (mod.$type === 'object') {
return mod
}
// "export default defineConfig(...)"
let config = resolveDefineConfig(mod)
if (config) {
return configView on GitHub (pinned to 1fa9837ec2)