{"id":"68129101e1cc7d7a","repo":"vitest-dev/vitest","slug":"root-project-is-not-initialized-this-means-that-t","errorCode":null,"errorMessage":"Root project is not initialized. This means that the Vite server was not established yet and the the workspace config is not resolved.","messagePattern":"Root project is not initialized\\. This means that the Vite server was not established yet and the the workspace config is not resolved\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/core.ts","lineNumber":592,"sourceCode":"  public getProvidedContext(): ProvidedContext {\n    return this.getRootProject().getProvidedContext()\n  }\n\n  /** @internal */\n  _ensureRootProject(): TestProject {\n    if (this.coreWorkspaceProject) {\n      return this.coreWorkspaceProject\n    }\n    this.coreWorkspaceProject = TestProject._createBasicProject(this)\n    return this.coreWorkspaceProject\n  }\n\n  /**\n   * Return project that has the root (or \"global\") config.\n   */\n  public getRootProject(): TestProject {\n    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    }","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/core.ts#L574-L610","documentation":"Thrown by Vitest.getRootProject() (packages/vitest/src/node/core.ts:592) when the internal coreWorkspaceProject is still null. That field is only assigned after the Vite dev server boots and the workspace config is resolved, so the error means initialization has not completed (or silently failed). Any accessor that needs the global/root config (serializedRootConfig, createCoverageProvider, mergeReports, etc.) routes through this getter.","triggerScenarios":"Calling vitest.getRootProject() or any API that depends on it before await vitest.start() / createVitest() has resolved; accessing it after the Vite server failed to come up so the workspace config never resolved.","commonSituations":"Programmatic API users who construct createVitest() and synchronously read getRootProject(); tests/integrations that race against initialization; a Vite server bootstrap error swallowed elsewhere so init never finished.","solutions":["Await vitest.start() (or the createVitest() promise) fully before calling getRootProject() or APIs that use it.","Verify the Vite server actually started — check for earlier thrown errors during init.","Guard the call: if (!vitest.coreWorkspaceProject) defer until the 'init' report hook fires."],"exampleFix":"// before\nconst vitest = createVitest('test')\nconst root = vitest.getRootProject() // throws\n\n// after\nconst vitest = await createVitest('test')\nconst root = vitest.getRootProject()","handlingStrategy":"validation","validationCode":"// ensure initialization finished before touching root project\nif (!vitest.coreWorkspaceProject) {\n  throw new Error('Vitest not initialized yet; await vitest.start() first')\n}\nconst root = vitest.getRootProject()","typeGuard":"function isVitestInitialized(vitest: Vitest): boolean {\n  return vitest.coreWorkspaceProject != null\n}","tryCatchPattern":null,"preventionTips":["Always await createVitest()/vitest.start() before reading projects.","Treat getRootProject() as post-init only; gate access on coreWorkspaceProject being set.","In integrations, subscribe to the 'init' reporter hook as the readiness signal."],"tags":["api-misuse","initialization","lifecycle","vite-server"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}