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

  1. Read the embedded ${message} to find the exact cause (it carries the inner error text).
  2. Fix the config so config.test.coverage.thresholds resolves to an object.
  3. 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

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

Related errors


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 config

View on GitHub (pinned to 1fa9837ec2)