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:
.mastra/output/package.json does not contain a direct zod dependency
.mastra/output/node_modules/zod/package.json resolves to 3.25.76
- root
import { z } from "zod" in .mastra/output has z.toJSONSchema === undefined
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
- Is this expected behavior for
mastra build?
- Should
.mastra/output/package.json preserve a direct zod dependency when the source app depends on it?
- Is there a supported way to force the generated output to retain app-level dependency constraints like
zod, overrides, or resolutions?
- 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.
Summary
When running
mastra build, the generated.mastra/outputartifact appears to lose the app's directzoddependency and package-manager constraints (overrides/resolutions). The resulting output installs rootzod@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:
Environment
1.3.91.3.0and1.3.13@mastra/core: originally1.9.0, then normalized to1.14.0zod:4.3.63.1.0What we observed
Our app package has a direct
zoddependency pinned to4.3.6. We also tested Bunoverridesandresolutionsforzod: 4.3.6.However after
mastra build:.mastra/output/package.jsondoes not contain a directzoddependency.mastra/output/node_modules/zod/package.jsonresolves to3.25.76import { z } from "zod"in.mastra/outputhasz.toJSONSchema === undefinedimport { z } from "zod/v4"still behaves like Zod v4So the built output ends up in a split state where:
zodresolves to 3.25.76 behaviorThat mismatch is enough to break downstream packages that assume root
zodmatches the schema flavor they receive.Minimal reproduction shape
After building, this reproduces from inside
.mastra/output:This throws:
because Stagehand imports root
zod, but.mastra/outputresolved that root package to3.25.76.Why this seems Mastra-related
The app package itself is pinned to Zod 4.3.6 and local checks outside
.mastra/outputbehave as expected. The drift appears duringmastra build/ generated output packaging.The surprising part is not that
3.25.76exists, but that:zodintent is not preserved in.mastra/output/package.jsonQuestions
mastra build?.mastra/output/package.jsonpreserve a directzoddependency when the source app depends on it?zod,overrides, orresolutions?zod@3.25.76package in build output, and if so, how should downstream packages safely interoperate with Zod v4 schemas?Happy to provide a smaller reproduction if useful.