vitest-dev/vitest · error · AggregateError
Errors occurred while running tests. For more information, s
Error message
Errors occurred while running tests. For more information, see serialized error.
What it means
AggregateError wrapping every rejected task promise from a single executeTests run. After all task groups (and browser specs) settle via Promise.allSettled, any rejected results are collected and re-thrown together so the caller sees one error carrying all underlying failures (accessible via error.errors). The message is a generic wrapper; the real diagnostics live on the contained errors and the serialized state reported to the UI/reporters.
Source
Thrown at packages/vitest/src/node/pool.ts:231
if (method === 'collect') {
promises.push(browserPool.collectTests(browserSpecs))
}
else {
promises.push(browserPool.runTests(browserSpecs))
}
}
const groupResults = await Promise.allSettled(promises)
results.push(...groupResults)
}
const errors = results
.filter(result => result.status === 'rejected')
.map(result => result.reason)
if (errors.length > 0) {
throw new AggregateError(
errors,
'Errors occurred while running tests. For more information, see serialized error.',
)
}
}
return {
name: 'default',
runTests: (files, invalidates) => executeTests('run', files, invalidates),
collectTests: (files, invalidates) => executeTests('collect', files, invalidates),
async close() {
await Promise.all([
pool.close(),
browserPool?.close?.(),
...ctx.projects.map(project => project.typechecker?.stop()),
])
},
}View on GitHub (pinned to d568f8ce37)
Solutions
- Inspect the AggregateError.errors array (or the serialized error in the reporter output) to find the root cause of each rejection.
- Fix the underlying test/setup/import error reported in the first contained error.
- Run a single failing file in isolation (vitest run path/to/file.test.ts) to reproduce without aggregation noise.
- Check vitest.state.getUnhandledErrors() / reporter 'unhandled error' output for worker-side context.
Example fix
// before: only see the aggregate message
try {
await pool.runTests(files)
}
catch (e) {
console.error(e.message) // 'Errors occurred while running tests...'
}
// after: surface each underlying error
try {
await pool.runTests(files)
}
catch (e) {
if (e instanceof AggregateError) {
for (const cause of e.errors) console.error(cause)
} else {
throw e
}
} Defensive patterns
Strategy: try-catch
Try / catch
// AggregateError-aware catch: surface each underlying cause
try {
await vitest.start()
} catch (e) {
const causes = e instanceof AggregateError ? e.errors : [e]
for (const cause of causes) console.error(cause)
process.exitCode = 1
} Prevention
- Treat each AggregateError.errors entry as the real failure to fix, not the wrapper message.
- Run the single failing file in isolation to drop aggregation noise.
- Wire reporters (junit/html) to capture per-file failures for triage.
When it happens
Trigger: One or more workers/browser tabs reject during pool.runTests or pool.collectTests in createPool (packages/vitest/src/node/pool.ts:221-235). Rejections include worker crashes, test-file load failures, environment setup errors inside a worker, or browser connection failures.
Common situations: A test file throws an uncaught exception during import/evaluation; a worker process exits unexpectedly (OOM, segfault); the browser pool fails to connect; a setup file errors. Anything that rejects a single task promise will surface here.
Related errors
- Expected string coverage payload, received ${typeof coverage
- The child process was torn down or never initialized. This i
- The worker thread was torn down or never initialized. This i
- Unexpected message ${JSON.stringify(message, null, 2)}
- Cannot provide "${key}" because it's not serializable.
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/0d06eccff3ec5243.json.
Report an issue: GitHub.