Registry / devops / esbuild-ajv

esbuild-ajv

JSON →
library0.0.1jsnpmunverified

esbuild plugin (v0.0.1, pre-1.0.0) to pre-compile Ajv JSON schemas at build time for faster runtime, CSP compliance, and smaller bundles. Pre-compilation avoids dynamic code generation (Function constructor), enabling use in environments with strict `unsafe-eval` CSP. Requires esbuild for building and Ajv v8 for schema compilation. Differentiates from runtime-only Ajv usage by moving compilation overhead to build step.

npm install esbuild-ajv
INSTALL
IMPORT
SIG · ESBUILD-AJV
E
esbuild-ajv
devopsjavascriptv0.0.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.

AjvPlugin
import AjvPlugin from 'esbuild-ajv'
const AjvPlugin = require('esbuild-ajv')
Default export; package is ESM-only. Use import statement.
PluginOptions
import AjvPlugin, { PluginOptions } from 'esbuild-ajv'
TypeScript type export for plugin options.
validator
import { validator } from './some.ajv.json'
import validator from './some.ajv.json'
Precompiled modules export a named export `validator`, not default.

Registers esbuild-ajv plugin in an esbuild build, passing Ajv options and extra keywords.

import esbuild from 'esbuild'; import AjvPlugin from 'esbuild-ajv'; await esbuild.build({ entryPoints: ['src/index.ts'], bundle: true, outfile: 'dist/bundle.js', plugins: [ AjvPlugin({ extraKeywords: [/* custom keyword definitions */], ajvOptions: { coerceTypes: true, useDefaults: true }, }), ], });
Debug
Known issues
breakingPre-1.0.0 version: API may change without major semver bump.
fix
Lock version to exact; review changelog before upgrading.
affects: <1.0.0
deprecatedAjv v8 is peer dependency; Ajv v7 is not supported.
fix
Ensure project uses `ajv@^8.0.0`.
affects: >=0.0.0
gotchaPlugin modifies esbuild resolve to treat `.ajv.json` imports specially; non-standard file extension.
fix
Use `.ajv.json` extension for schema files to be precompiled.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'esbuild-ajv'
esbuild-ajv not installed or not in node_modules.
fix
Run `npm install -D esbuild-ajv ajv`.
Module parse failed: Unexpected token (1:0) - file: .../.ajv.json
esbuild-ajv plugin not applied or esbuild cannot handle `.ajv.json` imports without plugin.
fix
Add `AjvPlugin()` to esbuild `plugins` array.
require() of ES Module esbuild-ajv not supported
Trying to use `require` with ESM-only package.
fix
Use `import AjvPlugin from 'esbuild-ajv'` instead of `require`.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies
ajvrequiredpeer dependency required for schema compilation and validation
Agent activity
2 hits · last 30 days
node
2
Resources