Registry / testing / ajv-dist

ajv-dist

JSON →
library8.17.1jsnpmunverified

This package provides pre-built browser bundles for Ajv, the fastest JSON Schema validator for Node.js and browsers (v8.17.1, stable). It is a companion package to ajv (v8.x), offering UMD and ESM builds for direct inclusion in HTML or bundlers, useful for environments without Node.js module resolution. Key differentiator: eliminates the need for a bundler step when using Ajv in browsers; it includes support for JSON Schema draft-07/2019-09/2020-12 and optional formats. Releases follow ajv releases with minor delays for bundle generation.

npm install ajv-dist
INSTALL
IMPORT
SIG · AJV-DIST
A
ajv-dist
testingjavascriptv8.17.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.

Ajv
import Ajv from 'ajv'
const Ajv = require('ajv')
Ajv is ESM-only since v8. Use dynamic import in CommonJS environments or use ajv-dist for browser script tags.
default export from ajv-dist
<script src="ajv/dist/ajv.min.js"></script> // then use window.Ajv
import Ajv from 'ajv-dist'
ajv-dist is meant for script tags or bundle imports; the UMD bundle exposes Ajv globally. For ES modules, import from 'ajv-dist/ajv.esm.js'.
ValidateFunction
import { ValidateFunction } from 'ajv'
import { ValidateFunction } from 'ajv-dist'
ajv-dist does not re-export types; you must import types from 'ajv'.

Shows how to use the UMD bundle in a browser to compile and validate a schema.

// Install: npm install ajv-dist // In HTML: <script src="node_modules/ajv/dist/ajv.min.js"></script> <script> const ajv = new Ajv(); const validate = ajv.compile({ type: 'object', properties: { foo: { type: 'string' }, bar: { type: 'number', minimum: 0 } }, required: ['foo', 'bar'] }); const valid = validate({ foo: 'test', bar: 1 }); if (!valid) console.error(validate.errors); else console.log('Valid!'); </script>
Debug
Known issues
deprecatedThe 'v5' option and JSON Schema v5 proposals are deprecated and removed in Ajv v8.
fix
Use standard JSON Schema drafts (07, 2019-09, 2020-12) instead.
affects: >=8.0.0
gotchaThe UMD bundle does not support strict mode by default; enabling strict mode may cause unexpected errors in browsers due to ignored keywords.
fix
Use the ESM bundle or set strict: false in options if you need to ignore unknown keywords.
affects: >=8.0.0
gotchaajv-dist bundles include only the core validator; optional formats (date, time, etc.) are not included and must be loaded separately.
fix
Either add the formats manually or use ajv-formats package and bundle it.
affects: >=8.0.0
breakingAjv v8 dropped support for older Node.js versions (below 10). If you need Node 6 or 8, stick with ajv v6.
fix
Use ajv v6 and ajv-dist v6.x for compatibility.
affects: >=8.0.0
Errors
Common errors & fixes
Ajv is not defined
The ajv-dist script tag not included or loaded before usage.
fix
Ensure <script src="path/to/ajv.min.js"></script> appears before any script using Ajv.
Cannot find module 'ajv'
Trying to import from 'ajv' in a browser environment without a bundler.
fix
Use ajv-dist instead: either use the UMD tag or import from 'ajv-dist/ajv.esm.js'.
TypeError: ajv.compile is not a function
Using Ajv instance incorrectly or the variable 'ajv' is the constructor, not an instance.
fix
Instantiate: const ajv = new Ajv(); then call ajv.compile(...).
unknown keyword "$comment"
Schema contains keywords not recognized by default; strict mode is on by default.
fix
Set addUsedSchema: false or strict: false, or use a draft that supports $comment (2019-09/2020-12).
Upgrade
Version history
8.17.1latest on npm
Audit
Dependencies
ajvrequiredAjv is the core validator; ajv-dist bundles it for browsers but does not include its own implementation.
Agent activity
46 hits · last 30 days
node
42
Amazon
1
OpenAI (training)
1
Resources
ajv-dist — npm install ajv-dist · libregistry