vitest-dev/vitest · error · Error
Root project is not initialized. This means that the Vite se
Error message
Root project is not initialized. This means that the Vite server was not established yet and the the workspace config is not resolved.
What it means
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.
Source
Thrown at packages/vitest/src/node/core.ts:592
public getProvidedContext(): ProvidedContext {
return this.getRootProject().getProvidedContext()
}
/** @internal */
_ensureRootProject(): TestProject {
if (this.coreWorkspaceProject) {
return this.coreWorkspaceProject
}
this.coreWorkspaceProject = TestProject._createBasicProject(this)
return this.coreWorkspaceProject
}
/**
* Return project that has the root (or "global") config.
*/
public getRootProject(): TestProject {
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.`)
}View on GitHub (pinned to d568f8ce37)
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.
Example fix
// before
const vitest = createVitest('test')
const root = vitest.getRootProject() // throws
// after
const vitest = await createVitest('test')
const root = vitest.getRootProject() Defensive patterns
Strategy: validation
Validate before calling
// ensure initialization finished before touching root project
if (!vitest.coreWorkspaceProject) {
throw new Error('Vitest not initialized yet; await vitest.start() first')
}
const root = vitest.getRootProject() Type guard
function isVitestInitialized(vitest: Vitest): boolean {
return vitest.coreWorkspaceProject != null
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Project "${name}" was not found.
- Page "${sessionId}" not found in ${this.browserName} browser
- [vitest] The provider was closed.
- Browser is not initialized
- Cannot find iframe with id ${event.iframeId}
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/68129101e1cc7d7a.json.
Report an issue: GitHub.