Registry / testing / joi-browser

joi-browser

JSON →
library13.4.0jsnpmunverified

joi-browser is a browser-ready bundle of the Joi object schema validation library (version 13.4.0, latest stable). It is pre-babelified and bundled for use in browsers with tools like Webpack or Browserify, avoiding the difficulties of bundling Joi natively. The package provides an ES5-compatible bundle and supports isomorphic/universal JavaScript by aliasing Joi in module bundlers. It requires polyfills for Promise and Map in older browsers and has an alternate 'joi-full' variant that includes date extensions. Community-driven alternative to native Joi, last updated in 2019.

npm install joi-browser
INSTALL
IMPORT
SIG · JOI-BROWSER
J
joi-browser
testingjavascriptv13.4.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.

default (Joi)
import Joi from 'joi-browser'
const Joi = require('joi')
Use joi-browser import in browser; on server, require 'joi' directly. For isomorphic setups, alias 'joi' to 'joi-browser' in bundler config.
Joi (CommonJS)
const Joi = require('joi-browser')
const joi = require('joi-browser').default
CommonJS require returns the default export directly, so no .default needed.
validate method
Joi.validate(value, schema, options)
schema.validate(value)
In Joi v13, .validate() is a static method on Joi, not on schema objects (changed from earlier versions).

Demonstrates basic schema validation using Joi's object schema, including .keys(), .string(), .number(), and validation with error checking.

// Install: npm install joi-browser // Polyfills for older browsers: npm install es6-promise es6-map require('es6-promise').polyfill(); require('es6-map/implement'); const Joi = require('joi-browser'); const schema = Joi.object().keys({ username: Joi.string().alphanum().min(3).max(30).required(), password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/), birthyear: Joi.number().integer().min(1900).max(2013), email: Joi.string().email({ minDomainSegments: 2 }) }).with('username', 'birthyear').without('password', 'access_token'); const data = { username: 'abc', birthyear: 1994 }; const result = Joi.validate(data, schema); // result.error === null, result.value === { username: 'abc', birthyear: 1994 }
Debug
Known issues
gotchajoi-browser is not an official Hapi.js package; it is a community fork. It may lag behind official Joi releases and may have different behavior.
fix
For latest Joi features, consider using the official 'joi' package with a polyfill or browser build.
affects: >=0.0.0
gotchaThe .validate() method on schema objects is deprecated in Joi v13; use Joi.validate() or the .validateAsync() method.
fix
Replace schema.validate(value) with Joi.validate(value, schema) or schema.validateAsync(value).
affects: >=13.0.0
gotchaRequires polyfills for Promise and Map in browsers that do not support ES6 (e.g., IE11). Without polyfills, errors like 'Promise is not defined' may occur.
fix
Include polyfills such as 'es6-promise' and 'es6-map' before loading joi-browser.
affects: >=0.0.0
gotchaWhen using Webpack with a Babel loader, joi-browser must be excluded from Babel transformation to avoid double-transpilation issues.
fix
In webpack config, add exclude: /joi-browser/ to the Babel loader rule.
affects: >=0.0.0
deprecatedThe default bundle is unminified; minified version is available as dist/bundle.min.js but may not be up to date.
fix
Use the default bundle for bundling; consider building your own minified version with your toolchain.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'joi-browser'
The module is not installed or the import path is incorrect; possibly using 'joi' instead of 'joi-browser' in browser code.
fix
Run 'npm install joi-browser' and ensure import statement uses 'joi-browser', not 'joi'.
TypeError: Joi.validate is not a function
The version of Joi used may be >13 where .validate() is no longer a static method; or the import is wrong (default vs named).
fix
Use Joi.validate() correctly: Joi.validate(value, schema). For Joi v16+, use schema.validateAsync(value).
ReferenceError: Promise is not defined
The browser environment lacks ES6 Promise support. joi-browser uses Promises internally.
fix
Add a Promise polyfill (e.g., 'es6-promise') before loading joi-browser.
Module build failed: Error: Cannot find module 'joi' (while using joi-browser)
Webpack/Browserify alias not configured; when using require('joi'), the bundler tries to resolve the original joi package.
fix
Configure alias in webpack (resolve.alias) or browserify (package.json browser field) as documented.
Upgrade
Version history
13.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
Resources
joi-browser — npm install joi-browser · libregistry