Registry / testing / zod-formik-adapter

zod-formik-adapter

JSON →
library2.0.0jsnpmunverified

A thin adapter that converts Zod validation schemas into Formik-compatible validationSchema or validate props. Current stable version is 2.0.0. This library bridges Zod 4.x with Formik 2.x, providing two main exports: toFormikValidationSchema and toFormikValidate. Unlike manual transformation, it handles error mapping automatically and preserves Zod's error details. It is essential when migrating from Yup to Zod in Formik projects.

npm install zod-formik-adapter
INSTALL
IMPORT
SIG · ZOD-FORMIK-ADAPTER
Z
zod-formik-adapter
testingjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

toFormikValidationSchema
import { toFormikValidationSchema } from 'zod-formik-adapter'
const toFormikValidationSchema = require('zod-formik-adapter').toFormikValidationSchema
ESM-only; use named import as shown.
toFormikValidate
import { toFormikValidate } from 'zod-formik-adapter'
import toFormikValidate from 'zod-formik-adapter'
Named export, not default.
z
import { z } from 'zod'
import { z } from 'zod-formik-adapter'
z is from Zod, not this package.

Basic usage integrating a Zod schema with Formik via toFormikValidationSchema.

import { z } from 'zod'; import { Formik, Form, Field } from 'formik'; import { toFormikValidationSchema } from 'zod-formik-adapter'; const schema = z.object({ name: z.string().min(1, 'Required'), age: z.number().min(0, 'Must be positive'), }); const MyForm = () => ( <Formik initialValues={{ name: '', age: 0 }} validationSchema={toFormikValidationSchema(schema)} onSubmit={(values) => console.log(values)} > <Form> <Field name="name" /> <Field name="age" type="number" /> <button type="submit">Submit</button> </Form> </Formik> );
Debug
Known issues
breakingVersion 2.0.0 requires Zod 4.x; incompatible with Zod 3.x.
fix
Downgrade to zod-formik-adapter@1.x if using Zod 3.x.
affects: >=2.0.0
deprecatedCommonJS require() is not supported; the package is ESM-only.
fix
Ensure your project uses ESM ("type": "module" in package.json) or use dynamic import().
affects: >=2.0.0
gotchaThe adapter does not transform the schema into a Yup shape; it only works in Formik's validationSchema or validate props.
fix
Do not attempt to use the output as a Yup schema; it is a function.
affects: >=1.0.0
gotchaErrors are mapped to Formik's format; custom error messages from Zod are preserved but structure may differ.
fix
Access errors via Formik's errors object; Zod's issues are flattened into field-level errors.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'zod-formik-adapter'
Package not installed or mismatched version requirement.
fix
Run npm install zod-formik-adapter formik zod@4
TypeError: toFormikValidationSchema is not a function
Incorrect import: using default import instead of named import.
fix
Use import { toFormikValidationSchema } from 'zod-formik-adapter'
Uncaught TypeError: Cannot read properties of undefined (reading 'parse')
Zod 3.x is installed instead of Zod 4.x.
fix
Upgrade Zod to version 4.x: npm install zod@4
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
formikrequiredPeer dependency; Formik provides the validation context and props that this adapter interfaces with.
zodrequiredPeer dependency; Zod provides the schema definition that the adapter transforms.
Agent activity
41 hits · last 30 days
node
32
Amazon
1
OpenAI (training)
1
Resources
zod-formik-adapter — npm install zod-formik-adapter · libregistry