tRPC Schema Migration

tRPC uses schema validation libraries to type-check procedure inputs and outputs. With tRPC v11's adoption of Standard Schema, you are no longer locked into Zod — but upgrading from Zod v3 to v4 or switching libraries requires careful attention to ecosystem compatibility. SchemaShift automates the migration and detects breaking dependencies.

Migration Paths

There are two common migration scenarios for tRPC projects:

Before & After: Zod v3 to v4

Most tRPC router code remains unchanged. The key differences are in Zod API changes:

Before (tRPC + Zod v3)
import { z } from 'zod';
import { router, publicProcedure }
  from './trpc';

const appRouter = router({
  getUser: publicProcedure
    .input(z.object({
      id: z.string(),
    }))
    .query(({ input }) => {
      return db.user.findUnique({
        where: { id: input.id }
      });
    }),

  createUser: publicProcedure
    .input(z.object({
      email: z.string().email(),
      role: z.nativeEnum(Role),
    }).strict())
    .mutation(({ input }) => {
      return db.user.create({ data: input });
    }),
});
After (tRPC + Zod v4)
import { z } from 'zod';
import { router, publicProcedure }
  from './trpc';

const appRouter = router({
  getUser: publicProcedure
    .input(z.object({
      id: z.string(),
    }))
    .query(({ input }) => {
      return db.user.findUnique({
        where: { id: input.id }
      });
    }),

  createUser: publicProcedure
    .input(z.strictObject({
      email: z.string().email(),
      role: z.enum(Role),
    }))
    .mutation(({ input }) => {
      return db.user.create({ data: input });
    }),
});

Key changes: z.nativeEnum() becomes z.enum(), and .strict() becomes z.strictObject(). SchemaShift handles 20+ breaking changes like these automatically.

Ecosystem Compatibility

SchemaShift's EcosystemAnalyzer detects third-party packages in your package.json that may break during migration and provides specific upgrade commands:

Package Issue Resolution
@trpc/server v10 Uses Zod v3 types internally Upgrade to @trpc/server@^11.0.0
trpc-openapi Depends on Zod v3 internals Needs v4-compatible version
trpc-ui Breaks with Zod v4 schemas Wait for v4-compatible update
zod-validation-error v4 breaks existing API npm install zod-validation-error@^5.0.0
zodios Zod-based HTTP client breaks with v4 Needs v4-compatible version
@ts-rest/core Uses Zod for contract definitions Check for v4-compatible release

Run schemashift migrate ./src -f zod-v3 -t v4 --compat-check to get a full compatibility report before proceeding with the migration.

Standard Schema and tRPC v11

tRPC v11 adopted the Standard Schema specification, which defines a common interface for schema validation libraries. This means tRPC now works with any conforming library:

This opens up the possibility of switching from Zod to a lighter alternative like Valibot (approximately 1kB gzipped vs Zod's 13kB) without losing tRPC compatibility.

Standard Schema Advisor

SchemaShift includes a StandardSchemaAdvisor that detects when both your source and target libraries support Standard Schema. It recommends whether to use an adapter approach (keeping both libraries temporarily) or a full migration, with generated code examples for tRPC v11 integration.

Migration Commands

# Upgrade Zod v3 to v4 with compatibility check
schemashift migrate ./src -f zod-v3 -t v4 --compat-check

# Use the tRPC preset for guided migration
schemashift migrate ./src --preset trpc-zod-v3-to-v4

# Switch from Zod to Valibot
schemashift migrate ./src -f zod -t valibot

# Analyze before migrating
schemashift analyze ./src --behavioral zod-v3-to-v4

Edge Cases & Gotchas

FAQ

Can I upgrade Zod to v4 in a tRPC project?

Yes, but you need tRPC v11 or later. tRPC v10 uses Zod v3 types directly in its internal type system, so upgrading Zod to v4 without upgrading tRPC will cause type errors. tRPC v11 adopted Standard Schema support, making it compatible with Zod v4, Valibot, ArkType, and other conforming libraries.

Does tRPC v11 work with schema libraries other than Zod?

Yes. tRPC v11 supports the Standard Schema specification, which means any library implementing the standard works out of the box. This includes Zod v3.23+, Zod v4, Valibot v1+, ArkType v2+, and Effect Schema. You can even use different schema libraries for different procedures in the same router.

What breaks when upgrading Zod in a tRPC project?

Common breaking changes include: trpc-openapi and trpc-ui packages that depend on Zod v3 internals, zod-validation-error needing v5.0.0+ for Zod v4, zodios HTTP client breaking with v4, and any code accessing Zod internal types like ZodType or ._def. SchemaShift's ecosystem analyzer detects all of these automatically and provides upgrade commands.

Related Migration Guides

Get Started

SchemaShift's ecosystem analyzer catches tRPC compatibility issues before they break your build. Run a compatibility check first, then migrate with confidence.

npm install -g schemashift-cli

The Zod v3 to v4 migration and ecosystem analysis require the Individual tier or above. View pricing.