{"id":"7075c3ad441ee250","repo":"vitest-dev/vitest","slug":"vitest-snapshot-couldn-t-infer-stack-frame-for-i","errorCode":null,"errorMessage":"@vitest/snapshot: Couldn't infer stack frame for inline snapshot.\n${message}","messagePattern":"@vitest/snapshot: Couldn't infer stack frame for inline snapshot\\.\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/snapshot/src/port/state.ts","lineNumber":272,"sourceCode":"  }\n\n  private _resolveInlineStack(options: {\n    testId: string\n    snapshot: string\n    assertionName: string\n    error: Error\n  }): ParsedStack {\n    const { testId, snapshot, assertionName, error } = options\n    const stacks = parseErrorStacktrace(\n      error,\n      { ignoreStackEntries: [] },\n    )\n    const _stack = this._inferInlineSnapshotStack(stacks)\n    if (!_stack) {\n      const message = stacks.map(s =>\n        `  ${s.file}:${s.line}:${s.column}${s.method ? ` (${s.method})` : ''}`,\n      ).join('\\n')\n      throw new Error(\n        `@vitest/snapshot: Couldn't infer stack frame for inline snapshot.\\n${message}`,\n      )\n    }\n    const stack = this.environment.processStackTrace?.(_stack) || _stack\n    // removing 1 column, because source map points to the wrong\n    // location for js files, but `column-1` points to the same in both js/ts\n    // https://github.com/vitejs/vite/issues/8657\n    stack.column--\n\n    // reject multiple inline snapshots at the same location if snapshot is different\n    const snapshotsWithSameStack = this._inlineSnapshotStacks.filter(s => isSameStackPosition(s, stack))\n    if (snapshotsWithSameStack.length > 0) {\n      // ensure only one snapshot will be written at the same location\n      this._inlineSnapshots = this._inlineSnapshots.filter(s => !isSameStackPosition(s, stack))\n\n      const differentSnapshot = snapshotsWithSameStack.find(s => s.snapshot !== snapshot)\n      if (differentSnapshot) {\n        throw Object.assign(","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/snapshot/src/port/state.ts#L254-L290","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the standard expect(...).toMatchInlineSnapshot() path so Vitest's __INLINE_SNAPSHOT__ marker is present.","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.","Disable mangling/dropping of function names in your transpiler (esbuild: keepNames: true; terser: keep_fnames: true).","If you need a custom offset, name a frame __INLINE_SNAPSHOT_OFFSET_<n>__ as documented in _inferInlineSnapshotStack."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function hasInlineSnapshotMarker(stack: { method: string }[]): boolean {\n  return stack.some(s =>\n    /__INLINE_SNAPSHOT__|__VITEST_EXTEND_ASSERTION__|__INLINE_SNAPSHOT_OFFSET_\\d+__|__VITEST_POLL_CHAIN__|__VITEST_(RESOLVES|REJECTS)__/.test(s.method),\n  )\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the built-in expect(...).toMatchInlineSnapshot() so Vitest's stack markers are preserved.","Keep function names in transpiled output (esbuild keepNames, terser keep_fnames).","When wrapping inline snapshots in custom matchers, reuse Vitest's chai plugin plumbing rather than rolling your own.","Avoid wrapping inline snapshot assertions in extra async layers that break the synchronous stack."],"tags":["snapshot","inline-snapshot","stack-trace","source-maps"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}