You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: Cannot read properties of undefined (reading 'onattach')
at <anonymous>
Node (--experimental-strip-types):hello
Any schema with a check (.min, .max, .length, .regex, .email, numeric .gt/.lt, …) hits this — z.string()/z.object().parse() without checks works.
Analysis
In zod's $ZodType initializer (node_modules/zod/src/v4/core/schemas.ts):
constchecks=[...(inst._zod.def.checks??[])];for(constchofchecks){for(constfnofch._zod.onattach){fn(inst);}// ch._zod is undefined}
A check instance in def.checks comes back without _zod. The check is built by new $ZodCheckMinLength({...}) (a $constructor that installs _zod via Object.defineProperty(inst, "_zod", { value, enumerable:false })), threaded through inst.check() → util.mergeDefs(def, { checks:[...] }) (which round-trips via Object.getOwnPropertyDescriptors + Object.defineProperties) → core.clone().
Not reproducible standalone: a faithful standalone model of the entire $constructor + $ZodCheck.init + onattach.push + mergeDefs (getOwnPropertyDescriptors/defineProperties round-trip) + [...def.checks] spread chain runs correctly in Perry (byte-matches Node). So the _zod loss is specific to the cross-module perry.compilePackages compilation of real zod — a check instance constructed in core/checks.ts and read back through core/schemas.ts / core/util.ts loses its non-enumerable _zod property somewhere across the module boundary.
Context
Follow-up to discussion #3438. The core object-parse crash (reading '_zod' of undefined) is fixed by #4697 (Object.defineProperty attribute retention); with that fix, z.object() / nested / array / boolean / optional parsing works. This checks-path bug and the safeParse error-path bug (separate issue) remain. Refs #793.
Activity
paulo-assoc commentedon Jun 7, 2026
I am blocked by this one.
fix(codegen): `new <imported-function>()` runs the constructor body (…
fix(codegen): `new <imported-function>()` runs the constructor body (…