M
MastraAI4w ago
leo

zod 4 support

i recently upgraded to zod 4 and upgraded all mastra packages as a i saw zod 4 is supported now. i am now running in this issue when running mastra dev
> mastra dev

◐ Preparing development environment...
✓ Initial bundle complete
◇ Starting Mastra dev server...
file:///Users/leopaz/dev/outlit/Core/node_modules/@mastra/core/dist/chunk-2ZSMA4EM.js:684
]),outputSchema:z.union([z.record(z.string(),z.any()),z.any()]).optional(),execute:z.function(z.tuple([z.any(),z.any()]),z.promise(z.any())).optional(),type:z.union([z.literal("function"),z.literal("provider-defined"),z.undefined()]).optional(),args:z.record(z.string(),z.any()).optional()});var storageThreadSchema=z.object({id:z.string(),title:z.string().optional(),resourceId:z.string(),createdAt:z.date(),updatedAt:z.date(),metadata:z.record(z.string(),z.any()).optional()});var prepareToolsStepOutputSchema=z.object({convertedTools:z.record(z.string(),coreToolSchema)});var prepareMemoryStepOutputSchema=z.object({threadExists:z.boolean(),thread:storageThreadSchema.optional(),messageList:z.instanceof(MessageList),tripwire:z.boolean().optional(),tripwireReason:z.string().optional()});// src/agent/workflows/prepare-stream/prepare-memory-step.ts
^

TypeError: z.function(...).optional is not a function
at file:///Users/leopaz/dev/outlit/Core/node_modules/@mastra/core/dist/chunk-2ZSMA4EM.js:684:142
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)

Node.js v22.16.0
> mastra dev

◐ Preparing development environment...
✓ Initial bundle complete
◇ Starting Mastra dev server...
file:///Users/leopaz/dev/outlit/Core/node_modules/@mastra/core/dist/chunk-2ZSMA4EM.js:684
]),outputSchema:z.union([z.record(z.string(),z.any()),z.any()]).optional(),execute:z.function(z.tuple([z.any(),z.any()]),z.promise(z.any())).optional(),type:z.union([z.literal("function"),z.literal("provider-defined"),z.undefined()]).optional(),args:z.record(z.string(),z.any()).optional()});var storageThreadSchema=z.object({id:z.string(),title:z.string().optional(),resourceId:z.string(),createdAt:z.date(),updatedAt:z.date(),metadata:z.record(z.string(),z.any()).optional()});var prepareToolsStepOutputSchema=z.object({convertedTools:z.record(z.string(),coreToolSchema)});var prepareMemoryStepOutputSchema=z.object({threadExists:z.boolean(),thread:storageThreadSchema.optional(),messageList:z.instanceof(MessageList),tripwire:z.boolean().optional(),tripwireReason:z.string().optional()});// src/agent/workflows/prepare-stream/prepare-memory-step.ts
^

TypeError: z.function(...).optional is not a function
at file:///Users/leopaz/dev/outlit/Core/node_modules/@mastra/core/dist/chunk-2ZSMA4EM.js:684:142
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)

Node.js v22.16.0
10 Replies
leo
leoOP4w ago
this is very critical for an update we're trying to push out. would appreciate promptness. here are my dependencies:
dependencies:
@mastra/client-js 0.13.2
@mastra/core 0.18.0
@mastra/deployer-vercel 0.12.2
@mastra/evals 0.13.8
@mastra/langfuse 0.0.9
@mastra/loggers 0.10.13
@mastra/mcp 0.13.1
@mastra/memory 0.15.3
@mastra/pg 0.16.1

devDependencies:
mastra 0.13.2
dependencies:
@mastra/client-js 0.13.2
@mastra/core 0.18.0
@mastra/deployer-vercel 0.12.2
@mastra/evals 0.13.8
@mastra/langfuse 0.0.9
@mastra/loggers 0.10.13
@mastra/mcp 0.13.1
@mastra/memory 0.15.3
@mastra/pg 0.16.1

devDependencies:
mastra 0.13.2
Mastra Triager
GitHub
[DISCORD:1421605038505070632] zod 4 support · Issue #8258 · mastr...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1421605038505070632 i recently upgraded to zod 4 and upgraded all mastra packages as a i saw zod 4 is supp...
_roamin_
_roamin_4w ago
Hi @leo ! Could you share a small repro example? Thanks 🙏
leo
leoOP4w ago
do you guys have a template i could base it off of?
_roamin_
_roamin_4w ago
If it's easily reproducible when using a fresh project created using npm create mastra@latest then you can just use that directly. You can also give us the steps to reproduce from a project created with npm create mastra@latest if that's easier. (depending on the bug, the template project is sometimes not good enough (e.g. monorepos)
leo
leoOP4w ago
okay will do that but zod 4 should work with the regular release right? theres no special tag or release i need to use?
_roamin_
_roamin_4w ago
It should work out of the box, if it doesn't then there is most likely a bug 😉
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
leo
leoOP4w ago
@salamanderxing your case seems like it could be a zod version mismatch issue. if you just upgraded make sure you don't have any zod 3 references in your mono repo or in any of your node_modulse
blank
blank4d ago
I had this issue too, ended up solving it by upgrading the Zod 4 versions in our mono repo from 4.0.x to 4.1.x Pretty sure this PR fixd it https://github.com/colinhacks/zod/pull/5121

Did you find this page helpful?