zod 4 toJSONSchema() throws a deferred SC2011 in finalize (Map entries spread)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript
- Domain
- compilers
Research direction
Start by reproducing with the minimal index.ts (a z.object calling toJSONSchema()) and the scriptc build command from the issue, then read the failing line 295 of node_modules/zod/v4/core/to-json-schema.js, which spreads ctx.seen.entries() in finalize. The payload does not name the compiler source that emits SC2011, so the first step is locating where that diagnostic is raised for untyped Map entries. Done means the probe prints the expected draft 2020-12 JSON Schema without the SC2011 error.
Written by the indexing model from the issue text.
Description
toJSONSchema() from zod 4.4.3 compiles, but throws at run time with a deferred SC2011 inside zod's finalize.
index.ts:
import { z } from "zod";
console.log(JSON.stringify(z.object({ a: z.string() }).toJSONSchema()));
With [email protected] installed and a tsconfig.json of {"compilerOptions":{"target":"ES2022","module":"NodeNext","moduleResolution":"NodeNext","strict":true}}, scriptc build index.ts -o probe --optimization dev --node-islands=off builds (0.4.10 and 0.4.11). Running ./probe:
scriptc: not compiled: values of type 'any' have no native representation at this site (instantiating 'finalize' with ({ counter: number; cycles: unknown; external: unknown; io: unknown; metadataR...)) [SC2011 at node_modules/zod/v4/core/to-json-schema.js:295]
Uncaught Error: values of type 'any' have no native representation at this site (instantiating 'finalize' with ...) [SC2011 at node_modules/zod/v4/core/to-json-schema.js:295]
at finalize (node_modules/zod/v4/core/to-json-schema.js:295:5)
Node prints {"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"a":{"type":"string"}},"required":["a"],"additionalProperties":false}.
Line 295 of to-json-schema.js is
for (const entry of [...ctx.seen.entries()].reverse()) {
where ctx.seen is a Map built in initializeContext (seen: new Map()), keyed by schema with untyped entry objects. The same happens through schema["~standard"].jsonSchema.input(...) and z.toJSONSchema(schema), which all reach finalize.
Programs that hand zod schemas to the MCP SDK (tool listings) or build structured-output prompts with z.toJSONSchema hit this.
- Dominant language
- TypeScript
- Stars
- 6.7k
- Forks
- 229
- Avg merge
- 14h 29m
- Merged PRs (30d)
- 787
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vercel-labs/scriptc
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
vercel-labs/scriptc#4865 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
vercel-labs/scriptc#4864 ·
Maintainers usually reply within 1 day
-
Windows ARM64 as a cross-compile targetPossibly taken @hum-n claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
vercel-labs/scriptc#4858 ·
Maintainers usually reply within 1 day
-
post-merge-bisect-unresolved
Difficulty 3/5 1-2 days Newbie friendliness 43/100
vercel-labs/scriptc#4791 ·
Maintainers usually reply within 1 day
-
post-merge-bisect-unconfirmed
Difficulty 5/5 Over a week Newbie friendliness 12/100
vercel-labs/scriptc#4755 · 1 comment ·
Maintainers usually reply within 1 day
All issues in vercel-labs/scriptc
Similar issues
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1293 ·
Maintainers usually reply within 1 day
-
area: middleware enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
agent/quality testing
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
juspay/agent-distro#203 ·
Maintainers usually reply within 1 day