vitest-dev/vitest · error · Error

Missing configurationFile. The "coverage.thresholds.autoUpda

Error message

Missing configurationFile. The "coverage.thresholds.autoUpdate" can only be enabled when configuration file is used.

What it means

coverage.thresholds.autoUpdate (coverage.ts:409) rewrites threshold numbers inside the user's config file, so it requires an actual config file on disk. When vite.config.configFile is null (config supplied inline or purely via CLI flags) vitest has nothing to rewrite and throws.

Source

Thrown at packages/vitest/src/node/coverage.ts:409

      (coverageMap as CoverageMap) || this.createCoverageMap(),
      allTestsRun,
    )

    // In watch mode we need to preserve the previous results if cleanOnRerun is disabled
    const keepResults = !this.options.cleanOnRerun && this.ctx.config.watch

    if (!keepResults) {
      await this.cleanAfterRun()
    }
  }

  async reportThresholds(coverageMap: CoverageMap, allTestsRun: boolean | undefined): Promise<void> {
    const resolvedThresholds = this.resolveThresholds(coverageMap)
    this.checkThresholds(resolvedThresholds)

    if (this.options.thresholds?.autoUpdate && allTestsRun) {
      if (!this.ctx.vite.config.configFile) {
        throw new Error(
          'Missing configurationFile. The "coverage.thresholds.autoUpdate" can only be enabled when configuration file is used.',
        )
      }

      const configFilePath = this.ctx.vite.config.configFile
      const configModule = await this.parseConfigModule(configFilePath)

      await this.updateThresholds({
        thresholds: resolvedThresholds,
        configurationFile: configModule,
        onUpdate: () =>
          writeFileSync(
            configFilePath,
            configModule.generate().code.replace(this.autoUpdateMarker, ''),
            'utf-8',
          ),

      })

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Create a vitest.config.ts (or vite.config.ts) on disk and enable autoUpdate there.
  2. Disable coverage.thresholds.autoUpdate for configless/inline runs.
  3. Write the inline config out to a temp file if autoUpdate is required.

Example fix

// before
createVitest('test', { test: { coverage: { thresholds: { autoUpdate: true } } } })

// after
createVitest('test', { configFile: './vitest.config.ts' })
// and in vitest.config.ts set test.coverage.thresholds.autoUpdate = true
Defensive patterns

Strategy: validation

Validate before calling

if (config.coverage.thresholds.autoUpdate && !viteConfig.configFile) {
  throw new Error('autoUpdate requires a config file on disk')
}

Type guard

function hasConfigFile(config: ResolvedConfig): boolean {
  return Boolean(config.configFile)
}

Prevention

When it happens

Trigger: Enabling coverage.thresholds.autoUpdate while running vitest configless — passing config inline via createVitest() or relying only on CLI flags, so no vitest.config.* / vite.config.* is resolved.

Common situations: Programmatic users passing a config object; CI that builds a config dynamically and never writes a file; examples using inline config.

Related errors


AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03). Data as JSON: /data/errors/3233b505db8f39b2.json. Report an issue: GitHub.