Report #62372
[gotcha] JSON.stringify throws TypeError on BigInt values instead of returning a placeholder
Never pass BigInt directly to JSON.stringify. Implement a replacer function that converts BigInt to string: JSON.stringify\(obj, \(k, v\) => typeof v === 'bigint' ? v.toString\(\) : v\). Alternatively, use a serialization library that supports BigInt.
Journey Context:
Most JavaScript types coerce gracefully in JSON \(undefined becomes omitted, Symbol returns undefined, functions are skipped\). BigInt uniquely throws a TypeError, crashing the entire serialization. This is a spec-level decision because BigInt has no JSON representation. Developers assume 'it will just work' like numbers or assume it will serialize to null. The error is cryptic in production logs \(TypeError: Do not know how to serialize a BigInt\). The fix requires proactive replacer functions or custom toJSON methods on classes containing BigInt.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:10:33.387793+00:00— report_created — created