{"record":{"id":"3233b505db8f39b2","repo":"vitest-dev/vitest","slug":"missing-configurationfile-the-coverage-threshold","errorCode":null,"errorMessage":"Missing configurationFile. The \"coverage.thresholds.autoUpdate\" can only be enabled when configuration file is used.","messagePattern":"Missing configurationFile\\. The \"coverage\\.thresholds\\.autoUpdate\" can only be enabled when configuration file is used\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/coverage.ts","lineNumber":409,"sourceCode":"      (coverageMap as CoverageMap) || this.createCoverageMap(),\n      allTestsRun,\n    )\n\n    // In watch mode we need to preserve the previous results if cleanOnRerun is disabled\n    const keepResults = !this.options.cleanOnRerun && this.ctx.config.watch\n\n    if (!keepResults) {\n      await this.cleanAfterRun()\n    }\n  }\n\n  async reportThresholds(coverageMap: CoverageMap, allTestsRun: boolean | undefined): Promise<void> {\n    const resolvedThresholds = this.resolveThresholds(coverageMap)\n    this.checkThresholds(resolvedThresholds)\n\n    if (this.options.thresholds?.autoUpdate && allTestsRun) {\n      if (!this.ctx.vite.config.configFile) {\n        throw new Error(\n          'Missing configurationFile. The \"coverage.thresholds.autoUpdate\" can only be enabled when configuration file is used.',\n        )\n      }\n\n      const configFilePath = this.ctx.vite.config.configFile\n      const configModule = await this.parseConfigModule(configFilePath)\n\n      await this.updateThresholds({\n        thresholds: resolvedThresholds,\n        configurationFile: configModule,\n        onUpdate: () =>\n          writeFileSync(\n            configFilePath,\n            configModule.generate().code.replace(this.autoUpdateMarker, ''),\n            'utf-8',\n          ),\n\n      })","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/coverage.ts#L391-L427","documentation":"coverage.thresholds.autoUpdate rewrites thresholds back into the config file on disk, so it requires an actual configFile. If vite.config.configFile is undefined (inline config, CLI-only, or programmatic createVitest without configFile), there is nothing to rewrite and it throws.","triggerScenarios":"Enabling coverage.thresholds.autoUpdate: true while running with no on-disk config file (inline config, programmatic API without configFile, or a run that resolved config from package.json/CLI only).","commonSituations":"Programmatic usage of createVitest; repos that use package.json or inline config; CI flag added without a config file present.","solutions":["Create a vitest.config.ts / vite.config.ts so vite.config.configFile resolves.","Disable coverage.thresholds.autoUpdate when no config file is available.","Pass configFile explicitly when using the programmatic API."],"exampleFix":"// before\nawait createVitest('test', {\n  config: { coverage: { thresholds: { autoUpdate: true, lines: 80 } } }\n})\n\n// after - create vitest.config.ts, then:\nawait createVitest('test', {\n  configFile: path.resolve('vitest.config.ts')\n})","handlingStrategy":"validation","validationCode":"function hasConfigFile(vitest) {\n  return typeof vitest.vite.config.configFile === 'string'\n}\n// before enabling autoUpdate: if (!hasConfigFile(vitest)) disable autoUpdate or create config","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create a vitest.config.ts whenever you enable coverage.thresholds.autoUpdate.","When using the programmatic API, pass configFile explicitly.","Disable autoUpdate for ad-hoc / inline-config runs."],"tags":["coverage","thresholds","config-file"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}