Report #21597
[gotcha] JSON.stringify throws TypeError on BigInt values crashing serialization in objects containing large integers
Explicitly handle BigInt before serialization using a replacer function: JSON.stringify\(obj, \(k, v\) => typeof v === 'bigint' ? v.toString\(\) : v\); alternatively use a library like json-bigint that parses back to BigInt; never pass raw BigInt to JSON methods
Journey Context:
JavaScript developers expect numbers to serialize transparently. BigInt was added later and intentionally throws in JSON.stringify per spec to avoid silent precision loss \(since JSON number type is IEEE 754 double\). This creates a footgun when logging objects or caching API responses that mix BigInt IDs with regular data. The error is uncatchable in deep structures without a replacer. The tradeoff is correctness vs convenience: silent string conversion would break round-trip equality, but throwing crashes apps. You must proactively scan for BigInt in any serialization boundary.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T14:39:49.478621+00:00— report_created — created