vitest-dev/vitest · error · Error

Cannot spawn child server without a parent dev server.

Error message

Cannot spawn child server without a parent dev server.

What it means

`ParentBrowserProject.spawn` creates a `ProjectBrowser` and copies `this.vite` into it. The check `if (!this.vite)` rejects the spawn when the parent's Vite dev server was never assigned via `setServer`, preventing a child from running without the shared dev server it depends on.

Source

Thrown at packages/browser/src/node/projectParent.ts:158

      resolve(distRoot, 'client/esm-client-injector.js'),
      'utf8',
    ).then(js => (this.injectorJs = js))
    this.errorCatcherUrl = join('/@fs/', resolve(distRoot, 'client/error-catcher.js'))

    this.matchersUrl = join('/@fs/', distRoot, 'expect-element.js')
    this.stateJs = readFile(
      resolve(distRoot, 'state.js'),
      'utf-8',
    ).then(js => (this.stateJs = js))
  }

  public setServer(vite: Vite.ViteDevServer): void {
    this.vite = vite
  }

  public spawn(project: TestProject): ProjectBrowser {
    if (!this.vite) {
      throw new Error(`Cannot spawn child server without a parent dev server.`)
    }
    const clone = new ProjectBrowser(
      this,
      project,
      '/',
    )
    this.children.add(clone)
    return clone
  }

  public parseErrorStacktrace(
    e: TestError,
    options: StackTraceParserOptions = {},
  ): ParsedStack[] {
    return parseErrorStacktrace(e, {
      ...this.stackTraceOptions,
      ...options,
    })

View on GitHub (pinned to d568f8ce37)

Solutions

  1. If you're calling `spawn` directly, call `parent.setServer(vite)` first.
  2. If this fires during a normal `vitest` run, update Vitest and `@vitest/browser` to matching versions and report the issue with a reproduction.
  3. Check that the browser plugin was registered (e.g. not disabled via config).

Example fix

// before
const parent = new ParentBrowserProject({ config, vitest }, '/')
parent.spawn(project)

// after
parent.setServer(viteDevServer)
parent.spawn(project)
Defensive patterns

Strategy: validation

Validate before calling

function assertParentReady(parent: { vite?: unknown }): void {
  if (!parent.vite) {
    throw new Error('Call parent.setServer(vite) before parent.spawn(project)')
  }
}

Type guard

const parentHasServer = (p: { vite?: unknown }): p is { vite: object } => !!p.vite

Prevention

When it happens

Trigger: Calling `parent.spawn(project)` before `parent.setServer(vite)` was invoked — an internal lifecycle violation.

Common situations: Internal Vitest bug or a custom orchestration layer that constructs `ParentBrowserProject` and calls `spawn` manually without first wiring the dev server. Standard Vitest runs always call `setServer` during plugin setup.

Related errors


AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03). Data as JSON: /data/errors/ad0a0ccd8a3f2031.json. Report an issue: GitHub.