Report #14823
[gotcha] JSON.stringify throws TypeError on BigInt values
Implement a replacer function that converts BigInt to string \(e.g., \`\(k, v\) => typeof v === 'bigint' ? v.toString\(\) : v\`\) or use a library that handles BigInt serialization explicitly.
Journey Context:
When using BigInt for 64-bit IDs or high-precision arithmetic, developers often forget that JSON has no BigInt type. The ECMAScript spec explicitly mandates a TypeError to prevent silent data corruption \(coercing to Number would lose precision\). The error surfaces when stringifying an object containing BigInt fields. Common mistakes include trying to use BigInt in fetch payloads without transformation. The replacer approach preserves precision by stringifying, with the client responsible for re-parsing using BigInt constructors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:27:40.106334+00:00— report_created — created