vitest-dev/vitest · error · AggregateError

Cannot resolve user fixtures. See errors for more informatio

Error message

Cannot resolve user fixtures. See errors for more information.

What it means

When `test.extend()`/`test.override()` registers fixtures via `parseUserFixtures` (fixture.ts:118), Vitest collects all validation errors (bad scope, unknown dependency, conflicting auto/scope, suite-level test-scoped fixture, etc.). If two or more distinct errors are found, they are bundled into an `AggregateError` with this message. A single error is thrown directly; this aggregate form is specifically for multiple simultaneous fixture problems.

Source

Thrown at packages/vitest/src/runtime/runner/fixture.ts:234

          continue
        }
        if (depName === fixture.name && !fixture.parent) {
          errors.push(new FixtureDependencyError(`The "${fixture.name}" fixture depends on itself, but does not have a base implementation.`))
          continue
        }

        if (TestFixtures._fixtureScopes.indexOf(fixture.scope) > TestFixtures._fixtureScopes.indexOf(dep.scope)) {
          errors.push(new FixtureDependencyError(`The ${fixture.scope} "${fixture.name}" fixture cannot depend on a ${dep.scope} fixture "${dep.name}".`))
          continue
        }
      }
    }

    if (errors.length === 1) {
      throw errors[0]
    }
    else if (errors.length > 1) {
      throw new AggregateError(errors, 'Cannot resolve user fixtures. See errors for more information.')
    }
    return registrations
  }
}

const cleanupFnArrayMap = new WeakMap<
  object,
  Array<() => void | Promise<void>>
>()

export async function callFixtureCleanup(context: object): Promise<void> {
  const cleanupFnArray = cleanupFnArrayMap.get(context) ?? []
  for (const cleanup of cleanupFnArray.reverse()) {
    await cleanup()
  }
  cleanupFnArrayMap.delete(context)
}

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Inspect `error.errors` (the AggregateError's sub-errors) to see each individual fixture problem.
  2. Fix each sub-error one at a time, starting with the first listed.
  3. Add fixtures incrementally to isolate which registration introduces errors.
  4. Verify every fixture dependency name exists and every `scope` value is one of 'test'|'file'|'worker'.

Example fix

// before: multiple bad fixtures
test.extend({
  a: [() => {}, { scope: 'testt' }],          // unknown scope
  b: ({ nonExistent }, use) => use(1),          // unknown dep
  c: [() => {}, { auto: true }],
  c2: [() => {}, { auto: false, scope: 'file' }],
})
// after: fix scope typo, remove unknown dep, align auto
test.extend({
  a: [() => {}, { scope: 'test' }],
  b: ({ a }, use) => use(a + 1),
})
Defensive patterns

Strategy: validation

Validate before calling

// Before test.extend, sanity-check fixture names and options.
const VALID_SCOPES = ['test', 'file', 'worker']
function preValidateFixtures(defs: Record<string, any>, known: Set<string>) {
  const errs: string[] = []
  for (const [name, def] of Object.entries(defs)) {
    const opts = Array.isArray(def) ? def[1] : {}
    if (opts?.scope && !VALID_SCOPES.includes(opts.scope)) errs.push(`${name}: bad scope`)
    // crude dep check omitted; rely on AggregateError for full graph
  }
  return errs
}

Try / catch

try {
  test.extend(newFixtures)
} catch (e) {
  if (e instanceof AggregateError) {
    for (const sub of e.errors) console.error(sub.message)
  } else throw e
}

Prevention

When it happens

Trigger: Registering several fixtures that each violate different rules at once — e.g. a fixture with an unknown scope, another depending on an undefined fixture, and a third with conflicting auto setting — all in one `test.extend({ ... })` call.

Common situations: Bulk fixture refactors introducing multiple regressions; typos in fixture option keys (`scope`, `auto`); renaming a fixture without updating dependents; copy-pasting fixtures into the wrong scope.

Related errors


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