vitest-dev/vitest · error · Error

Project "${name}" was not found.

Error message

Project "${name}" was not found.

What it means

Thrown by Vitest.getProjectByName(name) (core.ts:609). The lookup falls back through projects.find(name) → coreWorkspaceProject → projects[0]; this error fires only when the entire chain is empty, i.e. vitest has zero projects loaded. So a wrong name alone does NOT trigger it — being uninitialized (or having no projects) does.

Source

Thrown at packages/vitest/src/node/core.ts:609

    if (!this.coreWorkspaceProject) {
      throw new Error(`Root project is not initialized. This means that the Vite server was not established yet and the the workspace config is not resolved.`)
    }
    return this.coreWorkspaceProject
  }

  public get serializedRootConfig(): SerializedRootConfig {
    return {
      ...this.getRootProject().serializedConfig,
      projects: this.projects.map(project => project.serializedConfig),
    }
  }

  public getProjectByName(name: string): TestProject {
    const project = this.projects.find(p => p.name === name)
      || this.coreWorkspaceProject
      || this.projects[0]
    if (!project) {
      throw new Error(`Project "${name}" was not found.`)
    }
    return project
  }

  /**
   * Import a file using Vite module runner. The file will be transformed by Vite and executed in a separate context.
   * @param moduleId The ID of the module in Vite module graph
   */
  public import<T>(moduleId: string): Promise<T> {
    return this.runner.import(moduleId)
  }

  /**
   * Creates a coverage provider if `coverage` is enabled in the config.
   */
  public async createCoverageProvider(): Promise<CoverageProvider | null> {
    if (this._coverageProvider) {
      return this._coverageProvider

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Ensure await vitest.start() finished so projects are loaded.
  2. Confirm the workspace config actually defines projects (or a default project exists).
  3. Guard with vitest.projects.length before doing name lookups.

Example fix

// before
const p = vitest.getProjectByName('unit') // throws if no projects loaded

// after
await vitest.start()
if (vitest.projects.length === 0) throw new Error('no projects configured')
const p = vitest.getProjectByName('unit')
Defensive patterns

Strategy: validation

Validate before calling

await vitest.start()
if (vitest.projects.length === 0) {
  throw new Error('No projects loaded; check workspace config')
}
const p = vitest.getProjectByName(name)

Type guard

function hasProjects(vitest: Vitest): boolean {
  return vitest.projects.length > 0
}

Prevention

When it happens

Trigger: Calling getProjectByName(name) before initialization completed, or when the workspace defines no projects at all and coreWorkspaceProject is null.

Common situations: Calling the API too early in a programmatic integration; mergeReports() looking up a projectName while the projects array is still empty.

Related errors


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