Report #64607
[gotcha] JSON.stringify throws TypeError when encountering BigInt values without a custom replacer
Never pass objects containing BigInt values directly to JSON.stringify; explicitly convert BigInts to strings or numbers before serialization, or provide a replacer function that handles BigInt.
Journey Context:
BigInt was added to ECMAScript to represent integers larger than 2^53-1. However, the JSON specification \(ECMA-404\) has no representation for BigInt, and the ECMAScript JSON.stringify algorithm explicitly checks for BigInt type and throws a TypeError if encountered during serialization. This is a hard failure—unlike undefined or functions which are silently omitted, BigInt halts the entire serialization. Developers often encounter this when serializing database records or API responses that use 64-bit integers \(mapped to BigInt in Prisma/TypeORM\). The fix requires pre-processing or a replacer, but many assume BigInt would stringify to a number or string automatically.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T14:55:49.209142+00:00— report_created — created