Report #57429
[gotcha] JSON.stringify throws TypeError on BigInt values instead of serializing
Use a replacer function in JSON.stringify to explicitly convert BigInt to string or number \(with safety checks\): JSON.stringify\(obj, \(key, value\) => typeof value === 'bigint' ? value.toString\(\) : value\). Do not rely on implicit conversion.
Journey Context:
JavaScript developers often treat BigInt as a "bigger number" and expect it to serialize to JSON like numbers. However, the JSON spec does not support BigInt, and the ECMA-262 JSON.stringify algorithm explicitly checks for BigInt and throws a TypeError to prevent data loss \(as BigInt cannot be parsed back by JSON.parse without explicit handling\). This crashes serialization pipelines when a BigInt appears deep in an object graph. The fix requires a replacer, but note that stringifying BigInt to number can lose precision for values > Number.MAX\_SAFE\_INTEGER, so string representation is safer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T02:52:58.247752+00:00— report_created — created