Skip to content

[🐞] v2: zod$ crashes when the router resolves zod 4 β€” z.Schema was removed (instanceof TypeError, every action 500s)Β #8896

Description

@blakeley

Which component is affected?

Qwik Router

Describe the bug

The zod$ validator in @qwik.dev/router 2.0.0-beta.38 checks if (obj instanceof z.Schema) (lib/index.qwik.mjs, zodQrl.validate). z.Schema β€” a zod 3 alias of ZodType β€” no longer exists in zod 4. When the router's import ... from "zod" resolves to zod 4 (which happens in real-world hoisted layouts where the app itself depends on zod 4 and the package manager nests no private zod 3 copy for the router), every zod$-validated action throws server-side:

TypeError: Right-hand side of 'instanceof' is not an object
at zodQrl.validate (lib/index.qwik.mjs:1259)

and returns 500. Note the schema and the check use the SAME zod module (the router's re-exported z), so this isn't a mixed-versions problem β€” z.Schema is simply undefined in zod 4.

Reproduction

https://github.com/blakeley/zod4-zodschema-crash

Steps to reproduce

  1. bun install; if your package manager nested a private zod 3 under node_modules/@qwik.dev/router, remove just that copy to mirror hoisted-workspace layouts (README explains; in a real bun workspace no nested copy was produced)
  2. bun run dev
  3. POST the action: curl -s -o /dev/null -w '%{http_code}' -X POST "localhost:5173/?qaction=" -H 'Origin: http://localhost:5173' --data 'msg=hi' β†’ 500, server logs the TypeError
  4. Sanity: node -e "const z=require('zod'); console.log('Schema' in z, 'ZodType' in z)" β†’ false true

System Info

@qwik.dev/core 2.0.0-beta.38, @qwik.dev/router 2.0.0-beta.38, zod 4.4.3, vite 6, bun 1.2.17, macOS (darwin arm64), Node 22.

Additional Information

One-line fix verified empirically β€” obj instanceof z.ZodType works in zod 3 AND zod 4 (patched install turns the same POST into a 200). Related: PR #8887 touches the zod export for tree-shaking but keeps z.Schema.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions