vitest-dev/vitest · error · Error
Task instance was not found for
Error message
Task instance was not found for ${runnerTask.type} "${runnerTask.name}" What it means
Internal invariant in `getReportedTask`: a `RunnerTask` handed to the reporter layer must previously have been registered in `vitest.state.reportedTasksMap` via `storeTask`. A lookup miss means the task reached a reporter/callback without being stored first — a Vitest-internal state desync, not a user configuration problem.
Solutions
- Align all `@vitest/*` packages to the same version (`pnpm update -r @vitest/*@vitest/*`).
- Disable custom reporters/plugins one by one to isolate which one touches the task lifecycle.
- If it reproduces with stock Vitest, file an issue with the task `type`, `name`, and a minimal reproduction.
Defensive patterns
Strategy: try-catch
Try / catch
// In a custom reporter: guard task lookups so a missing reported entity doesn't kill the run.
function safeReportedTask(project, runnerTask) {
try {
return project.vitest.state.getReportedEntity(runnerTask)
} catch {
return null
}
} Prevention
- Keep all `@vitest/*` packages on the same released version.
- Prefer the public reporter event payloads over reaching into `vitest.state` for raw runner tasks.
- If you build a custom reporter, register every task through the documented lifecycle before reading it.
When it happens
Trigger: A reporter or plugin iterating runner tasks receives a `RunnerTask` whose type/name was never passed through `storeTask`; typically arises from custom reporters/hooks that bypass the normal task lifecycle, or from a version mismatch between `vitest` and `@vitest/runner`/reporter packages.
Common situations: Third-party reporter plugins reading raw runner tasks; concurrent/sharded runs hitting a race; mixed `@vitest/*` package versions after a partial upgrade.
Related errors
- Assertion name is not set. This is a bug in Vitest. Please…
- Blob reporter is not supported in watch mode
- Browser is not initialized
- Cannot find iframe element. This is a bug in Vitest…
- Custom reporter loaded from
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/8758b46771599e50.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/node/reporters/reported-tasks.ts:779
*/
readonly workerId: number
}
function storeTask(
project: TestProject,
runnerTask: RunnerTask,
reportedTask: TestCase | TestSuite | TestModule,
): void {
project.vitest.state.reportedTasksMap.set(runnerTask, reportedTask)
}
function getReportedTask(
project: TestProject,
runnerTask: RunnerTask,
): TestCase | TestSuite | TestModule {
const reportedTask = project.vitest.state.getReportedEntity(runnerTask)
if (!reportedTask) {
throw new Error(
`Task instance was not found for ${runnerTask.type} "${runnerTask.name}"`,
)
}
return reportedTask
}
function getSuiteState(task: RunnerTestSuite | RunnerTestFile): TestSuiteState {
const mode = task.mode
const state = task.result?.state
if (mode === 'skip' || mode === 'todo' || state === 'skip' || state === 'todo') {
return 'skipped'
}
if (state == null || state === 'run' || state === 'only') {
return 'pending'
}
if (state === 'fail') {
return 'failed'
}View on GitHub (pinned to 1fa9837ec2)