Registry / testing / valibot

valibot

JSON →
library1.4.1jsnpmunverified

Valibot is a modular, type-safe schema validation library for JavaScript and TypeScript, designed as a lightweight alternative to Zod. Version 1.4.1 ships with full TypeScript support, zero dependencies, and a tree-shakable modular architecture that starts at under 700 bytes. It provides both exception-based parsing (parse) and safe parsing (safeParse, is), along with 100% test coverage. The library distinguishes itself by enabling up to 95% bundle size reduction compared to Zod through tree-shaking. It requires TypeScript >=5. The API is based on many small, independent functions rather than a monolithic class, making it easily extensible. Stable release cadence with active development on GitHub.

npm install valibot
INSTALL
IMPORT
SIG · VALIBOT
V
valibot
testingjavascriptv1.4.1
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.

default import (all as v)
import * as v from 'valibot'
import v from 'valibot'
Valibot does not export a default namespace. Use namespace import.
parse
import { parse } from 'valibot'
const parse = require('valibot').parse
Tree-shaking works best with named imports. CommonJS also supported.
object, string, pipe, email, minLength
import { object, string, pipe, email, minLength } from 'valibot'
Import individual functions for optimal tree-shaking.
InferOutput
import { InferOutput } from 'valibot'
import type { InferOutput } from 'valibot'
InferOutput is a type (value and type). Both work.
safeParse
import { safeParse } from 'valibot'
Returns a result object, does not throw.

Creates a login schema with email and password validation, parses data, and demonstrates safe parsing with error handling.

import * as v from 'valibot'; // Define a schema const LoginSchema = v.object({ email: v.pipe(v.string(), v.email()), password: v.pipe(v.string(), v.minLength(8)), }); // Infer TypeScript type type LoginData = v.InferOutput<typeof LoginSchema>; // Parse with exception const result = v.parse(LoginSchema, { email: 'test@example.com', password: '12345678' }); console.log(result); // { email: 'test@example.com', password: '12345678' } // Safe parse const safeResult = v.safeParse(LoginSchema, { email: 'bad', password: 'short' }); if (safeResult.success) { console.log(safeResult.output); } else { console.log(safeResult.issues); }
Debug
Known issues
breakingv1.0.0 changes API from v0.x: parse now throws by default; use safeParse for non-throwing.
fix
Replace custom error handling with safeParse or catch errors from parse.
affects: >=1.0.0
breakingv1.0.0 removed the 'parseAsync' function; use parse with async schemas or pipe.
fix
Use parse() which supports async validators natively.
affects: >=1.0.0
gotchaEmail validation (v.email()) does not reject all invalid emails; it follows HTML5 spec.
fix
Use additional string validators like v.regex(/.../) for stricter checks.
affects: *
deprecatedv.recursive() is deprecated; use v.lazy() with object schemas.
fix
Replace v.recursive(() => ...) with v.lazy(() => ...).
affects: >=1.0.0 <2.0.0
gotchaTree-shaking only works if imports are from 'valibot' (not 'valibot/core' etc).
fix
Always import from the main package: import { object } from 'valibot'.
affects: *
Errors
Common errors & fixes
Cannot find module 'valibot' or its corresponding type declarations.
Missing TypeScript version >=5 or incorrect import path.
fix
Ensure typescript@>=5 is installed and import from 'valibot', not 'valibot/...'.
TypeError: v.parse is not a function
Using default import (import v from 'valibot') instead of namespace import.
fix
Use import * as v from 'valibot' or import { parse } from 'valibot'.
SchemaError: Invalid schema received
Passing a non-schema value to parse() or passing undefined/null where object is expected.
fix
Ensure the first argument is a valid schema created with valibot functions like v.object().
Upgrade
Version history
1.4.1latest on npm
Audit
Dependencies
typescriptoptionalPeer dependency; Valibot relies on TypeScript >=5 for type inference and schema definitions.
Agent activity
9 hits · last 30 days
node
8
Resources
valibot — npm install valibot · libregistry