{"record":{"id":"f8deb04259631f13","repo":"vitest-dev/vitest","slug":"project-name-was-not-found","errorCode":null,"errorMessage":"Project \"${name}\" was not found.","messagePattern":"Project \"(.+?)\" was not found\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/core.ts","lineNumber":608,"sourceCode":"    if (!this.coreWorkspaceProject) {\n      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.`)\n    }\n    return this.coreWorkspaceProject\n  }\n\n  public get serializedRootConfig(): SerializedRootConfig {\n    return {\n      ...this.getRootProject().serializedConfig,\n      projects: this.projects.map(project => project.serializedConfig),\n    }\n  }\n\n  public getProjectByName(name: string): TestProject {\n    const project = this.projects.find(p => p.name === name)\n      || this.coreWorkspaceProject\n      || this.projects[0]\n    if (!project) {\n      throw new Error(`Project \"${name}\" was not found.`)\n    }\n    return project\n  }\n\n  /**\n   * Import a file using Vite module runner. The file will be transformed by Vite and executed in a separate context.\n   * @param moduleId The ID of the module in Vite module graph\n   */\n  public import<T>(moduleId: string): Promise<T> {\n    return this.runner.import(moduleId)\n  }\n\n  /**\n   * Creates a coverage provider if `coverage` is enabled in the config.\n   */\n  public async createCoverageProvider(): Promise<CoverageProvider | null> {\n    if (this._coverageProvider) {\n      return this._coverageProvider","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/core.ts#L590-L626","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst project = vitest.getProjectByName(name)\n\n// after\nif (vitest.projects.length === 0) {\n  throw new Error('No projects registered; cannot resolve ' + name)\n}\nconst exists = vitest.projects.some(p => p.name === name)\nconst project = exists\n  ? vitest.projects.find(p => p.name === name)\n  : vitest.projects[0]","handlingStrategy":"validation","validationCode":"function canResolveProject(vitest, name) {\n  if (vitest.projects.length === 0) return false\n  if (name == null || name === '') return true // fallback to projects[0]/coreWorkspaceProject\n  return vitest.projects.some(p => p.name === name) || !!vitest.coreWorkspaceProject\n}\n// call before: if (!canResolveProject(vitest, name)) handleMissing()","typeGuard":"function hasProjects(v): v is { projects: { name: string }[] } {\n  return Array.isArray(v.projects) && v.projects.length > 0\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["projects","merge-reports","api-misuse"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}