Skip to content

mastra build output resolves root zod to 3.25.76 and drops app-level zod constraints #14460

@rowan-aldean-verifast

Description

@rowan-aldean-verifast

Summary

When running mastra build, the generated .mastra/output artifact appears to lose the app's direct zod dependency and package-manager constraints (overrides / resolutions). The resulting output installs root zod@3.25.76, which can create a runtime mismatch when the bundled app code is producing Zod v4 schemas.

In our case this breaks Stagehand at runtime with:

Error: Zod v4 toJSONSchema method not found
    at .../@browserbasehq/stagehand/dist/esm/lib/v3/zodCompat.js:15:11

Environment

  • Bun: 1.3.9
  • Mastra CLI: tested with 1.3.0 and 1.3.13
  • @mastra/core: originally 1.9.0, then normalized to 1.14.0
  • App zod: 4.3.6
  • Stagehand: 3.1.0

What we observed

Our app package has a direct zod dependency pinned to 4.3.6. We also tested Bun overrides and resolutions for zod: 4.3.6.

However after mastra build:

  1. .mastra/output/package.json does not contain a direct zod dependency
  2. .mastra/output/node_modules/zod/package.json resolves to 3.25.76
  3. root import { z } from "zod" in .mastra/output has z.toJSONSchema === undefined
  4. import { z } from "zod/v4" still behaves like Zod v4

So the built output ends up in a split state where:

  • bundled app code is effectively using Zod v4-style schemas
  • runtime root zod resolves to 3.25.76 behavior

That mismatch is enough to break downstream packages that assume root zod matches the schema flavor they receive.

Minimal reproduction shape

After building, this reproduces from inside .mastra/output:

import { z } from './node_modules/zod/v4/index.js';
import { toJsonSchema } from './node_modules/@browserbasehq/stagehand/dist/esm/lib/v3/zodCompat.js';

toJsonSchema(z.object({ ok: z.boolean() }));

This throws:

Error: Zod v4 toJSONSchema method not found

because Stagehand imports root zod, but .mastra/output resolved that root package to 3.25.76.

Why this seems Mastra-related

The app package itself is pinned to Zod 4.3.6 and local checks outside .mastra/output behave as expected. The drift appears during mastra build / generated output packaging.

The surprising part is not that 3.25.76 exists, but that:

  • app-level zod intent is not preserved in .mastra/output/package.json
  • Bun constraints from the source package do not appear to carry into the generated output

Questions

  1. Is this expected behavior for mastra build?
  2. Should .mastra/output/package.json preserve a direct zod dependency when the source app depends on it?
  3. Is there a supported way to force the generated output to retain app-level dependency constraints like zod, overrides, or resolutions?
  4. Does Mastra intentionally rely on the transitional zod@3.25.76 package in build output, and if so, how should downstream packages safely interoperate with Zod v4 schemas?

Happy to provide a smaller reproduction if useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIIssues regarding Mastra CLI commands: Build, Dev, Start etcMastra ServerIssues related to the Mastra Server or its handlersbugSomething isn't workingeffort:highimpact:hightrio-wp

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions