Node.js 24.11.1 breaks console.error() when logging ZodError in 3.25.76
Issue
Node.js 24.11.1 introduced a regression that causes console.error() to crash when logging ZodError objects.
Zod: 3.25.76
Crash:
TypeError: Cannot read properties of undefined (reading 'value')
at formatProperty (node:internal/util/inspect:2279:12)
at formatRaw (node:internal/util/inspect:1176:9)
at formatValue (node:internal/util/inspect:932:10)
at inspect (node:internal/util/inspect:409:10)
Reproduction
import { z } from "zod";
const schema = z.object({ name: z.string() }).optional();
try { schema.parse("invalid"); } catch (error) { console.error(error); // Crashes in Node 24.11.1 }## Upstream Bug Report
Node.js issue: ~~https://github.com/nodejs/node/issues/60948 (this was duplicate)~~ https://github.com/nodejs/node/issues/60717
Workarounds
Until Node.js fixes this regression:
Option 1: Downgrade Node.js to 24.11.0
Option 2: Use a safe logging wrapper
function safeConsoleError(message, obj) {
if (typeof obj === "object") {
console.error(message, JSON.stringify(obj, null, 2));
} else {
console.error(message, obj);
}
}
catch (error) {
safeConsoleError("Validation error:", error);
}
Option 3: Use console.log instead
catch (error) {
console.log(error); // Works fine
}
Testing Results
- ✅ Node 24.11.0: Works correctly
- ❌ Node 24.11.1: Crashes
- ✅ Node 24.10.x and earlier: Works correctly
Note
This is a Node.js regression, not a zod bug. Filing here for visibility to help zod users encountering this issue until the Node.js team releases a fix.
I've been hit with this issue too on v25.2.1
Something that could be changed in Zod to improve the situation for broken versions: cause and errors properties are by default own properties. For ZodErrors, that is not always the case and it broke due to matching inherited properties (that will not be visible in newer Node.js versions anymore).