vitest-dev/vitest · error · Error

The file " " must start with "vitest.config"/"vite.config"…

Error message

The file "${relative(parentConfig.root, file)}" must start with "vitest.config"/"vite.config" or match the pattern "(vitest|vite).*.config.*" to be a valid project config.

What it means

A file referenced directly by a `projects` string must satisfy Vitest's config naming convention (`CONFIG_REGEXP`): the basename must start with `vitest.config`/`vite.config` or match `(vitest|vite).*.config.*`. This stops arbitrary modules (test files, setup files) from being loaded as project configs.

Solutions

  1. Rename the file to follow `vitest.config.*` / `vite.config.*` (or `(vitest|vite).*.config.*`, e.g. `vitest.unit.config.ts`).
  2. If the file genuinely isn't a project config, remove it from `projects`.

Example fix

// before
export default defineConfig({ test: { projects: ['./test-setup.ts'] } })

// after: rename the file on disk to vitest.config.ts (or vite.config.ts)
export default defineConfig({ test: { projects: ['./vitest.config.ts'] } })
Defensive patterns

Strategy: validation

Validate before calling

import { basename } from 'node:path'
const CONFIG_REGEXP = /^(vitest|vite)(\..*)?\.config\..+$/

function assertProjectsFileNamed(root: string, projects: unknown[]) {
  for (const def of projects) {
    if (typeof def !== 'string' || /[*/?]/.test(def)) continue
    const file = resolve(root, def)
    const name = basename(file)
    if (existsSync(file) && statSync(file).isFile() && !CONFIG_REGEXP.test(name)
        && !(name.startsWith('vitest.config') || name.startsWith('vite.config'))) {
      throw new Error(`'${name}' is not a valid project config name; rename to vitest.config.*/vite.config.*.`)
    }
  }
}

Prevention

When it happens

Trigger: `projects: ['./setup.ts']` where `basename(file)` fails `CONFIG_REGEXP.test(name)` after the file passed the existence check.

Common situations: Pointing `projects` at a setup file, a test file, or a config with a non-standard name (e.g. `vit.config.ts`).

Related errors


AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11). Data as JSON: /api/errors/0f5640a129e2471d. Report an issue: GitHub.

Appendix: source

Thrown at packages/vitest/src/node/projects/resolveProjects.ts:1190

  for (const definition of projectsDefinition) {
    if (typeof definition === 'string') {
      const stringOption = definition.replace('<rootDir>', parentConfig.root)
      // if the string doesn't contain a glob, we can resolve it directly
      // ['./vitest.config.js']
      if (!isDynamicPattern(stringOption)) {
        const file = resolve(parentConfig.root, stringOption)

        if (!existsSync(file)) {
          throw new Error(`Projects definition references a non-existing file or a directory: ${file}`)
        }

        const stats = statSync(file)
        // user can specify a config file directly
        if (stats.isFile()) {
          const name = basename(file)
          if (!CONFIG_REGEXP.test(name)) {
            throw new Error(
              `The file "${relative(parentConfig.root, file)}" must start with "vitest.config"/"vite.config" `
              + `or match the pattern "(vitest|vite).*.config.*" to be a valid project config.`,
            )
          }

          projectsConfigFiles.push(file)
        }
        // user can specify a directory that should be used as a project
        else if (stats.isDirectory()) {
          const configFile = resolveDirectoryConfig(file)
          if (configFile) {
            projectsConfigFiles.push(configFile)
          }
          else {
            const directory = file.at(-1) === '/' ? file : `${file}/`
            nonConfigProjectDirectories.push(directory)
          }
        }

View on GitHub (pinned to 1fa9837ec2)