Report #91392
[gotcha] JSON.stringify throws TypeError on BigInt values
Use a replacer function to convert BigInt to string: JSON.stringify\(obj, \(key, value\) => typeof value === 'bigint' ? value.toString\(\) : value\). Alternatively, use a library like json-bigint that preserves precision.
Journey Context:
BigInt is a distinct primitive type from Number, introduced in ES2020. The JSON specification \(RFC 8259\) and ECMA-262 explicitly state that BigInt cannot be serialized to JSON \(as JSON numbers are IEEE 754 doubles\). Therefore, JSON.stringify must throw a TypeError when encountering BigInt, rather than silently converting to string or number. This often crashes production logging when database IDs are BigInt. The replacer function is the spec-compliant workaround.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T11:59:37.982113+00:00— report_created — created