| | |

Zod 30 🛡️ Zod Mini — zod/mini for tree-shakable React bundles

⏱️ Estimated read: 9 min | |

Zod Mini is a tree-shakable variant of Zod that implements the same validation functionality with a functional API instead of chained methods. The change is a bundler optimization: methods attached to schema objects cannot be removed by tree-shaking, but top-level functions can. The result is a bundle that includes only the functions the application actually calls, and the measured reduction is roughly 64% for a simple schema and 70% for an object schema .

This chapter covers the import path, the functional API that replaces method chaining, the measured bundle sizes, and the cases where Zod Mini is and is not the right choice. The sections that follow walk through the API difference, the React Hook Form integration, and the decision criteria that the Zod documentation itself recommends.

Key point: zod/mini is imported as import * as z from "zod/mini" and uses functions like z.optional(z.string()) instead of z.string().optional(); the bundle is 64–70% smaller, but the API is more verbose and the documentation recommends regular Zod unless bundle size is an uncommonly strict constraint.


a. The import path and the functional API

Zod Mini is a subpath export of the zod package. The import is import * as z from "zod/mini"; the older zod/v4-mini path also works, but the canonical form is the subpath without the version prefix . The standalone @zod/mini package re-exports the same API from a peer dependency on zod, and its version tracks the main package .

The API difference is mechanical. Where regular Zod chains methods, Zod Mini wraps the base schema in functions. The chained .min() and .max() become the z.minLength() and z.maxLength() functions passed to .check(), and .optional() becomes the z.optional() wrapper .

// Regular Zod: method chaining
const Schema = z.string().min(5).max(10).trim().optional();

// Zod Mini: functional composition
import * as z from "zod/mini";

const Schema = z.optional(
  z.string().check(
    z.minLength(5),
    z.maxLength(10),
    z.trim()
  )
);

The functional form is what makes the tree-shaking work. A bundler can see that z.optional and z.minLength are imported and remove every other function from the bundle. In regular Zod, the methods are attached to the ZodString prototype, and the bundler cannot remove individual methods from a class it cannot analyze .

The validation results are identical. Both schemas accept the same values and produce the same ZodError issues. The difference is the bundle, not the behavior.


b. Measured bundle sizes and the trade-off

The Zod documentation provides two measurements that frame the decision. For a trivial z.boolean().parse(true) schema, the gzipped bundle is 2.12 KB with Zod Mini and 5.91 KB with regular Zod, a 64% reduction. For a marginally complex object schema with string, number, and boolean fields, the sizes are 4.0 KB and 13.1 KB, a 69% reduction .

SchemaZod Mini (gzip)Zod (gzip)Reduction
z.boolean().parse(true)2.12 KB5.91 KB64%
Object with 3 fields4.0 KB13.1 KB69%

The trade-off is developer experience. The documentation is direct about this: “The API of Zod Mini is more verbose and less discoverable. The methods in Zod’s API are much easier to discover & autocomplete through Intellisense than the top-level functions in Zod Mini. It isn’t possible to quickly build a schema with chained APIs” . The Zod creator states a preference for the standard API despite designing the Mini API to be as ergonomic as possible.

The documentation also pushes back on the assumption that bundle size is always the priority. The Lambda cold-start benchmark shows that a 17 KB bundle adds roughly 0.6 ms to a 171 ms baseline, and the round-trip time to a server (100–200 ms) dwarfs the download time for an additional 10 KB except on slow 3G connections . The recommendation is to use regular Zod unless the application is specifically optimizing for users in rural or developing areas with slow mobile networks.


c. React Hook Form integration and the decision

Zod Mini works with zodResolver from @hookform/resolvers v5.1.0 and later. The resolver was updated to support Zod v4, Zod Mini, and v3 through the Standard Schema interface, so the integration is the same zodResolver(schema) call regardless of which variant the schema uses . The only difference is the schema definition: the Mini schema is built with the functional API, and the resolver treats it as a Standard Schema.

import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import * as z from "zod/mini";

const Schema = z.object({
  name: z.string().check(z.minLength(1)),
  age: z.number().check(z.minimum(0), z.maximum(150)),
});

type SchemaType = z.infer<typeof Schema>;

const form = useForm<SchemaType>({
  resolver: zodResolver(Schema),
});

The standardSchemaResolver is an alternative, but the Zenn article notes that it fixes the useForm generics and prevents the original type from being set, which is a significant drawback for form development . The zodResolver path is recommended because it supports the generics.

The decision criteria, restated from the documentation :

ConditionRecommendation
Server-side validationRegular Zod (bundle size irrelevant)
Typical client applicationRegular Zod (DX matters more)
Bundle-size-critical client (slow networks, rural/developing areas)Zod Mini
Edge functions with tight size limitsZod Mini

The unplugin-zod-to-mini package exists for projects that want the Mini bundle without rewriting the schemas: it transforms regular Zod schemas to Mini at build time . The transformer is an option for a codebase that already has regular Zod schemas and wants the smaller client bundle without the API migration.


Complete Example Session

// ============================================
// PART 1: THE REGULAR ZOD VERSION
// ============================================
import * as z from "zod";

const RegularSchema = z.object({
  email: z.string().email(),
  age: z.number().int().min(0).max(150),
  nickname: z.string().min(1).optional(),
});

// ============================================
// PART 2: THE ZOD MINI VERSION
// ============================================
import * as z from "zod/mini";

const MiniSchema = z.object({
  email: z.string().check(z.email()),
  age: z.number().check(z.int(), z.minimum(0), z.maximum(150)),
  nickname: z.optional(z.string().check(z.minLength(1))),
});

// ============================================
// PART 3: THE PARSED RESULT IS IDENTICAL
// ============================================
// Both schemas accept the same values and produce the same issues.
// The difference is the bundle, not the behavior.

// ============================================
// PART 4: THE REACT HOOK FORM INTEGRATION
// ============================================
// resolver: zodResolver(MiniSchema) works with @hookform/resolvers >= 5.1.0

The parts covered the regular version, the Mini version, the identical parse behavior, and the resolver compatibility.


Quick Reference

Import Paths

PathVariant
import * as z from "zod"Regular Zod (v4)
import * as z from "zod/mini"Zod Mini
import * as z from "zod/v4-mini"Zod Mini (legacy path)
@zod/miniStandalone re-export

API Difference

Regular ZodZod Mini
z.string().min(5)z.string().check(z.minLength(5))
z.string().optional()z.optional(z.string())
z.number().int()z.number().check(z.int())
z.string().trim()z.string().check(z.trim())

Bundle Sizes

SchemaMiniRegular
z.boolean()2.12 KB5.91 KB
3-field object4.0 KB13.1 KB

Best Practices

✅ Do This:

// Use zod/mini only when bundle size is critical
import * as z from "zod/mini";                              // ✅

// Use the functional API
z.optional(z.string().check(z.minLength(1)))                 // ✅

// Keep zodResolver for React Hook Form
resolver: zodResolver(MiniSchema)                            // ✅

❌ Don’t Do This:

// Use Mini on the server
// (bundle size is irrelevant there)                          // ❌

// Assume Mini is faster at runtime
// (it is smaller, not faster)                               // ❌

// Use standardSchemaResolver for typed forms
// (generics are lost)                                       // ❌

Common Pitfalls

PitfallWhy It HappensFix
Importing Mini but using chained methodsMuscle memory from regular ZodUse z.check() functions
Resolver incompatibility@hookform/resolvers < 5.1.0Upgrade to 5.1.0+
Mini on the server for no benefitAssumed size always mattersUse regular Zod on the backend
Generics lost with standardSchemaResolverResolver limitationUse zodResolver

Real-World Examples

1. Mini import

import * as z from "zod/mini";

2. Optional string

z.optional(z.string());

3. String with checks

z.string().check(z.minLength(5), z.maxLength(10));

4. Number with checks

z.number().check(z.int(), z.minimum(0));

5. Object schema

z.object({ name: z.string().check(z.minLength(1)) });

6. React Hook Form resolver

resolver: zodResolver(MiniSchema)

7. Build-time transform

// unplugin-zod-to-mini transforms regular → mini

8. Edge function

// Mini for bundle-size-constrained runtimes

9. Regular Zod on server

import * as z from "zod"; // server code

10. Version tracking

// @zod/mini version tracks zod

Visual

Tree-Shaking Comparison

┌─────────────────────────────────────────────────────────┐
│  REGULAR ZOD                                            │
│  ┌──────────────────────────────────────────┐           │
│  │ ZodString.prototype.min                  │           │
│  │ ZodString.prototype.max                  │           │
│  │ ZodString.prototype.trim                 │           │
│  │ ZodString.prototype.email                │           │
│  │ ... all methods bundled                  │           │
│  └──────────────────────────────────────────┘           │
│  Bundler cannot remove individual methods               │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│  ZOD MINI                                               │
│  ┌──────────────────────────────────────────┐           │
│  │ import { minLength, maxLength }          │           │
│  │ ... only imported functions bundled      │           │
│  └──────────────────────────────────────────┘           │
│  Bundler removes unused top-level functions             │
└─────────────────────────────────────────────────────────┘

Bundle Size

┌─────────────────────────────────────────────────────────┐
│  SIMPLE SCHEMA                                          │
│  Mini:    ██ 2.12 KB                                    │
│  Regular: ██████ 5.91 KB                                │
│                                                         │
│  OBJECT SCHEMA                                          │
│  Mini:    ████ 4.0 KB                                   │
│  Regular: █████████████ 13.1 KB                         │
│                                                         │
│  64–69% reduction                                       │
└─────────────────────────────────────────────────────────┘

Decision Tree

┌─────────────────────────────────────────────────────────┐
│  Is this client-side code?                              │
│         │                                               │
│    ┌────┴────┐                                          │
│    ▼         ▼                                          │
│   YES        NO                                         │
│    │         │                                          │
│    ▼         ▼                                          │
│  Bundle      Regular Zod                                │
│  critical?   (size irrelevant)                          │
│    │                                                    │
│ ┌──┴──┐                                                 │
│ ▼     ▼                                                 │
│ YES    NO                                               │
│ │      │                                                │
│ ▼      ▼                                                │
│ Mini   Regular                                          │
│        (DX wins)                                        │
└─────────────────────────────────────────────────────────┘

Summary

ItemValue
Importimport * as z from "zod/mini"
API styleFunctional (z.optional(z.string()))
Bundle reduction64–69%
React Hook FormzodResolver with @hookform/resolvers >= 5.1.0
Recommended forBundle-size-critical client code
Not recommended forServer code, typical client apps

Key takeaways:

  • Zod Mini is the same functionality with a functional API. The validation behavior is identical; the difference is that the functions are top-level and therefore tree-shakable .
  • The bundle reduction is real but situational. A simple schema drops from 5.91 KB to 2.12 KB, and an object schema from 13.1 KB to 4.0 KB. The documentation recommends regular Zod unless bundle size is an uncommonly strict constraint .
  • The API is more verbose. Chained methods become nested function calls, and the documentation acknowledges the developer experience trade-off. The Zod creator states a preference for the standard API .
  • React Hook Form works with both. The zodResolver supports Mini through the Standard Schema interface, provided @hookform/resolvers is 5.1.0 or later .
  • The decision is about the client, not the codebase. Server-side Zod has no bundle-size concern; the Mini variant is for the client bundle that ships to the user, specifically when the user base has slow network connections .

Remember: Zod Mini is a bundle optimization, not a behavioral change. The schema validates the same values and produces the same errors. The choice is between a smaller bundle and a more verbose API. Use it on the client when the bundle size is the constraint, keep regular Zod on the server where it is not, and do not assume that the smaller bundle makes the application faster—the documentation’s benchmarks show the download time is dwarfed by the round-trip time except on slow connections.

Was this helpful?


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!