Report #4199
[gotcha] JSON.stringify throws TypeError when encountering BigInt values instead of serializing them
Wrap JSON.stringify in try-catch for defensive logging, or use a replacer function: JSON.stringify\(obj, \(k, v\) => typeof v === 'bigint' ? v.toString\(\) : v\); consider using a structured logging library that handles BigInt natively
Journey Context:
Unlike other types that JSON.stringify silently ignores \(functions, undefined, symbols\), BigInt throws a TypeError. This crashes production error reporters and telemetry systems when they try to serialize error objects containing BigInt IDs or timestamps \(common with Snowflake IDs or nanosecond timestamps\). The error happens at serialization time, not at the point where BigInt was introduced, making it hard to trace. The replacer function is the spec-compliant fix, but must be applied consistently. Alternatives like 'flatted' or 'serialize-javascript' handle this but are slower.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:59:29.074202+00:00— report_created — created