vitest-dev/vitest · error · Error

@vitest/snapshot: Couldn't infer stack frame for inline snap

Error message

@vitest/snapshot: Couldn't infer stack frame for inline snapshot.
${message}

What it means

Thrown by SnapshotState._resolveInlineStack() when _inferInlineSnapshotStack() returns null — Vitest could not find any of the known marker frames (__INLINE_SNAPSHOT__, __VITEST_EXTEND_ASSERTION__, __INLINE_SNAPSHOT_OFFSET_<n>__, __VITEST_POLL_CHAIN__, __VITEST_RESOLVES/REJECTS__) in the parsed error stack. Inline snapshots need a precise source location to rewrite the test file, so without an inferable frame the update is aborted and the parsed stack is dumped for diagnosis.

Source

Thrown at packages/snapshot/src/port/state.ts:272

  }

  private _resolveInlineStack(options: {
    testId: string
    snapshot: string
    assertionName: string
    error: Error
  }): ParsedStack {
    const { testId, snapshot, assertionName, error } = options
    const stacks = parseErrorStacktrace(
      error,
      { ignoreStackEntries: [] },
    )
    const _stack = this._inferInlineSnapshotStack(stacks)
    if (!_stack) {
      const message = stacks.map(s =>
        `  ${s.file}:${s.line}:${s.column}${s.method ? ` (${s.method})` : ''}`,
      ).join('\n')
      throw new Error(
        `@vitest/snapshot: Couldn't infer stack frame for inline snapshot.\n${message}`,
      )
    }
    const stack = this.environment.processStackTrace?.(_stack) || _stack
    // removing 1 column, because source map points to the wrong
    // location for js files, but `column-1` points to the same in both js/ts
    // https://github.com/vitejs/vite/issues/8657
    stack.column--

    // reject multiple inline snapshots at the same location if snapshot is different
    const snapshotsWithSameStack = this._inlineSnapshotStacks.filter(s => isSameStackPosition(s, stack))
    if (snapshotsWithSameStack.length > 0) {
      // ensure only one snapshot will be written at the same location
      this._inlineSnapshots = this._inlineSnapshots.filter(s => !isSameStackPosition(s, stack))

      const differentSnapshot = snapshotsWithSameStack.find(s => s.snapshot !== snapshot)
      if (differentSnapshot) {
        throw Object.assign(

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Use the standard expect(...).toMatchInlineSnapshot() path so Vitest's __INLINE_SNAPSHOT__ marker is present.
  2. In custom matchers, name the assertion wrapper appropriately or use the existing Vitest plumbing (chai plugin) rather than calling the snapshot client from a plain function.
  3. Disable mangling/dropping of function names in your transpiler (esbuild: keepNames: true; terser: keep_fnames: true).
  4. If you need a custom offset, name a frame __INLINE_SNAPSHOT_OFFSET_<n>__ as documented in _inferInlineSnapshotStack.
Defensive patterns

Strategy: validation

Validate before calling

function hasInlineSnapshotMarker(stack: { method: string }[]): boolean {
  return stack.some(s =>
    /__INLINE_SNAPSHOT__|__VITEST_EXTEND_ASSERTION__|__INLINE_SNAPSHOT_OFFSET_\d+__|__VITEST_POLL_CHAIN__|__VITEST_(RESOLVES|REJECTS)__/.test(s.method),
  )
}

Prevention

When it happens

Trigger: Using toMatchInlineSnapshot inside a custom matcher that does not preserve the chai stack markers; transpilers/bundlers stripping function names or rewriting the call stack; calling inline snapshot assertion through a Proxy or async boundary that breaks stack parsing; source-map configuration that collapses frames.

Common situations: Custom expect.extend matchers that wrap toMatchInlineSnapshot without using the __VITEST_EXTEND_ASSERTION__ wrapper; esbuild/swc settings that drop function names; async utilities that lose the synchronous stack; mixing inline snapshots with manual Promise constructors.

Related errors


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