{"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":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/core.ts","lineNumber":609,"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":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/core.ts#L591-L627","documentation":"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.","triggerScenarios":"Calling getProjectByName(name) before initialization completed, or when the workspace defines no projects at all and coreWorkspaceProject is null.","commonSituations":"Calling the API too early in a programmatic integration; mergeReports() looking up a projectName while the projects array is still empty.","solutions":["Ensure await vitest.start() finished so projects are loaded.","Confirm the workspace config actually defines projects (or a default project exists).","Guard with vitest.projects.length before doing name lookups."],"exampleFix":"// before\nconst p = vitest.getProjectByName('unit') // throws if no projects loaded\n\n// after\nawait vitest.start()\nif (vitest.projects.length === 0) throw new Error('no projects configured')\nconst p = vitest.getProjectByName('unit')","handlingStrategy":"validation","validationCode":"await vitest.start()\nif (vitest.projects.length === 0) {\n  throw new Error('No projects loaded; check workspace config')\n}\nconst p = vitest.getProjectByName(name)","typeGuard":"function hasProjects(vitest: Vitest): boolean {\n  return vitest.projects.length > 0\n}","tryCatchPattern":null,"preventionTips":["Confirm projects are loaded before name lookups (vitest.projects.length > 0).","Remember getProjectByName falls back to projects[0]; only an empty list actually throws.","Validate the workspace config defines projects in CI smoke tests."],"tags":["api-misuse","projects","initialization"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}