{"record":{"id":"d8cc49643d9f2b77","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/1fa9837ec26533512fdcad8baebf249771bd340a/packages/snapshot/src/port/state.ts#L254-L290","documentation":"When recording/updating an inline snapshot, SnapshotState._resolveInlineStack parses the assertion's Error stack and calls _inferInlineSnapshotStack to find the frame pointing at the assertion call site. If no suitable frame can be inferred (e.g. stack empty, all frames filtered, source maps unmapped), it cannot compute the line/column to write the snapshot into and throws, listing the candidate frames for diagnosis.","triggerScenarios":"Inline snapshot (toMatchInlineSnapshot) update where the error stack is empty or all frames are ignored; source maps missing or broken so parsed frames do not match the source file; stack-stripping/minification removing the relevant frame; running in an environment that does not capture real stack traces.","commonSituations":"Bundled/transpiled code with broken source maps; custom stack-trace parser filtering too aggressively; minified production build of tests; runtime without Error.captureStackTrace; async boundary that lost the original frame.","solutions":[],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Before recording, sanity-check that the error has a usable stack\nif (!error.stack && !error.stackTrace) throw new Error('cannot infer inline snapshot frame: error has no stack')","typeGuard":"function hasUsableStack(e: Error): boolean { try { return parseErrorStacktrace(e, { ignoreStackEntries: [] }).length > 0 } catch { return false } }","tryCatchPattern":"try {\n  // assertion that records inline snapshot\n} catch (e) {\n  if (e instanceof Error && /Couldn't infer stack frame for inline snapshot/.test(e.message)) {\n    // fall back: write the snapshot manually with toMatchInlineSnapshot('...')\n  } else throw e\n}","preventionTips":["Generate source maps in test builds (sourcemap: true)","Avoid minifying test bundles","Keep ignoreStackEntries permissive for snapshot frames","Manually populate inline snapshots when stacks are unreliable"],"tags":["snapshot","inline","stack-trace","source-map"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}