MastraM
Mastra2w ago
anurag

[BUG] Mastra dev server crashes with "Package subpath './v4' is not defined" when using Zod 3.x

The mastra dev command fails to start when Zod 3.25.76 is installed, attempting to import a non-existent zod/v4 subpath.

Environment
• Mastra version: 0.18.6
@mastra/core version: 0.24.6
• Zod version: 3.25.76
• Node version: 22.13.0
• Package manager: npm (monorepo)

Steps to Reproduce
  1. Install Mastra with Zod 3.25.76
  2. Run npm run dev (which runs mastra dev)
  3. Server crashes during initializationErrorError [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './v4' is not defined by "exports" in mastra-app/node_modules/zod/package.json imported from mastra-app/.mastra/output/index.mjs at exportsNotFound (node:internal/modules/esm/resolve:314:10) at packageExportsResolve (node:internal/modules/esm/resolve:662:9)Root CauseMastra is attempting to import zod/v4 subpath, which only exists in Zod 4.x:✅ Zod 4.1.x: Exports zod/v4 subpath❌ Zod 3.x: Does not export zod/v4 subpathExpected BehaviorMastra should:
  4. Option A: Auto-detect Zod version and use correct imports (zod for v3, zod/v4 for v4)
  5. Option B: Explicitly require Zod 4.x in peer dependencies if v4-specific features are needed
  6. Option C: Avoid importing zod/v4 and use standard zod import that works with both versionsContextAccording to the [Mastra changelog (2025-09-08)](https://mastra.ai/blog/changelog-2025-09-08), Zod v4 support was added while maintaining full v3 compatibility. However, the import pathzod/v4 breaks that compatibility.Workaround Attempted• Tried upgrading to Zod 4.1.13, but this breaks AI SDK compatibility: `AI_APICallError: tools.0.custom.input_schema.type: Field required`(See issue #7234 for context on Zod 4 schema conversion issues)
Was this page helpful?