Report #70821
[gotcha] JSON.stringify throws TypeError on BigInt values instead of returning null/undefined
Never pass BigInt to JSON.stringify directly. Implement a replacer function that converts BigInt to string or number, or use a serialization library that handles BigInt.
Journey Context:
Unlike undefined or functions which are silently omitted in JSON, BigInt throws a TypeError when stringified because there's no standard JSON representation for arbitrary precision integers. This is a deliberate spec choice \(ECMA-262 26.5.2.2\) to prevent accidental precision loss. Developers often expect it to serialize as a number or string, or at least be skipped like undefined, but the hard throw crashes entire serialization pipelines. The fix requires explicit handling via a replacer function \(key, value\) => typeof value === 'bigint' ? value.toString\(\) : value, acknowledging that the consumer must know to parse it back.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:27:21.908304+00:00— report_created — created