vitest-dev/vitest · error
Project " " was not found.
Error message
Project "${name}" was not found. What it means
Thrown by Vitest's getProjectByName when no project can be resolved. Note the implementation silently falls back to coreWorkspaceProject then projects[0] before throwing, so the error only actually fires when the workspace has zero projects AND coreWorkspaceProject is undefined. The message names the requested project, but the true root cause is an empty/missing project list rather than a name typo. It is most often surfaced indirectly via mergeReports, which calls getProjectByName(file.projectName || '') for every blob file.
Solutions
- Ensure at least one project is configured/loaded before calling getProjectByName or mergeReports.
- When merging reports, run the merge in a workspace whose project names match the blobs (re-add the referenced projects to config).
- If calling programmatically, guard with vitest.projects.length > 0 (and the specific name) before invoking.
Example fix
// before
const project = vitest.getProjectByName(name)
// after
if (vitest.projects.length === 0) {
throw new Error('No projects registered; cannot resolve ' + name)
}
const exists = vitest.projects.some(p => p.name === name)
const project = exists
? vitest.projects.find(p => p.name === name)
: vitest.projects[0] Defensive patterns
Strategy: validation
Validate before calling
function canResolveProject(vitest, name) {
if (vitest.projects.length === 0) return false
if (name == null || name === '') return true // fallback to projects[0]/coreWorkspaceProject
return vitest.projects.some(p => p.name === name) || !!vitest.coreWorkspaceProject
}
// call before: if (!canResolveProject(vitest, name)) handleMissing() Type guard
function hasProjects(v): v is { projects: { name: string }[] } {
return Array.isArray(v.projects) && v.projects.length > 0
} Prevention
- Before mergeReports, ensure the workspace's project names match those referenced by the blobs.
- When calling getProjectByName programmatically, assert vitest.projects.length > 0 first.
- Treat an empty projects array as a fatal setup error early, rather than letting downstream lookups fail.
When it happens
Trigger: Calling getProjectByName(name) (directly or via mergeReports) when this.projects is empty and this.coreWorkspaceProject is undefined. Internally mergeReports calls this.getProjectByName(file.projectName || '') for each blob, so a blob that references a project while the workspace has no registered projects triggers it.
Common situations: Running --merge-reports in a workspace whose blobs reference projects not configured there; calling the API programmatically before projects are registered; using mergeReports against blobs produced by a different project layout.
Related errors
- A function to advance timers was called but the timers APIs…
- Cannot merge reports when `--reporter=blob` is used. Remove…
- Cannot merge reports with --watch enabled
- expected must be a function, received
- Failed to initialize projects. There were errors during…
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/f8deb04259631f13.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/node/core.ts:608
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._coverageProviderView on GitHub (pinned to 1fa9837ec2)