vitest-dev/vitest · error · Error
Task instance was not found for ${runnerTask.type} "${runner
Error message
Task instance was not found for ${runnerTask.type} "${runnerTask.name}" What it means
Thrown by `getReportedTask` (reported-tasks.ts:779) when a runner task (the low-level `RunnerTask` from the test runner) is looked up in `project.vitest.state.reportedTasksMap` / via `getReportedEntity` but no reported entity has been registered for it. This is an internal invariant: every runner task that the reporter layer processes must have been stored first via `storeTask`. Encountering it indicates a state-tracking bug or out-of-order access inside Vitest rather than a user configuration problem.
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 d568f8ce37)
Solutions
- If you hit this in app code, report a Vitest bug with a minimal reproduction (it signals an internal consistency violation).
- In custom reporters, only access reported tasks during/after the hooks that guarantee they exist (e.g. `onTestRunEnd`, `onTaskUpdate`) rather than early lifecycle hooks.
- Upgrade to the latest patch release; this kind of invariant break is typically fixed quickly.
Defensive patterns
Strategy: try-catch
Try / catch
try {
const entity = project.vitest.state.getReportedEntity(runnerTask)
if (!entity) return // guard instead of letting Vitest throw
// ... use entity
} catch (e) {
if (e instanceof Error && /Task instance was not found/.test(e.message)) {
// skip tasks without reported entities
} else throw e
} Prevention
- In custom reporters, prefer the reported-task APIs handed to your hooks over re-deriving entities from runner tasks.
- Only access reported entities during hooks that guarantee their existence.
- Guard with `state.getReportedEntity(task)` truthiness before use.
When it happens
Trigger: A custom reporter calling APIs that walk runner tasks before the reported-task map is populated; an internal ordering change where a task event arrives before its `storeTask` call; mutating or reusing runner task objects across Vitest instances.
Common situations: Building a custom reporter that touches `experimental_getRunnerTask` / internal task state at the wrong lifecycle hook; running against an in-development Vitest build with a regression in task tracking.
Related errors
- Unknown suite state: ${state}
- Task ${id} was not found
- Test specification for task ${id} was not found
- Cannot find iframe with id ${event.iframeId}
- Cannot spawn child server without a parent dev server.
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/8758b46771599e50.json.
Report an issue: GitHub.