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.
validateSchema
✓ const validateSchema = require('yaml-schema-validator')
✗ import validateSchema from 'yaml-schema-validator'
Package is CommonJS only; ES import syntax may fail.
validateSchema
✓ const { validateSchema } = require('yaml-schema-validator')
✗ const validateSchema = require('yaml-schema-validator').default
No default export; must use named destructuring or direct assignment (the whole module is the function).
Schema
✓ const { Schema } = require('yaml-schema-validator')
✗ const Schema = require('yaml-schema-validator').Schema
Schema constructor for defining custom validators with .use and .message.
Demonstrates three validation methods: file vs schema file, object vs schema object, and object vs reference object.
const validateSchema = require('yaml-schema-validator');
// Validate a YAML file against a schema file
const errors = validateSchema('target.yml', {
schemaPath: 'schema.yml'
});
if (errors.length > 0) {
console.log('Validation errors:', errors);
} else {
console.log('Validation passed');
}
// Validate a plain object against a JS schema object
const person = { name: { first: 'Tom', last: 'Xoman' }, age: 45 };
const requiredSchema = {
name: {
first: { type: String, required: true },
last: { type: String, required: true }
},
age: { type: Number }
};
const schemaErrors = validateSchema(person, { schema: requiredSchema });
console.log(schemaErrors);
// Validate using an ideal object's structure (schemaObj)
const idealPerson = { name: { first: 'Tom', last: 'Xoman' }, age: 45 };
const compareErrors = validateSchema(person, { schemaObj: idealPerson });
console.log(compareErrors);
Errors
Common errors & fixes
TypeError: validateSchema is not a function
Attempting to use ES import or destructuring incorrectly on a CommonJS module.
fixUse `const validateSchema = require('yaml-schema-validator')` Cannot find module 'yaml-schema-validator'
Package not installed or running in an environment without node_modules.
fixRun `npm install yaml-schema-validator` and ensure you are in the correct directory.
ENOENT: no such file or directory, open 'schema.yml'
The file path provided to schemaPath or target does not exist.
fixProvide absolute paths or ensure the relative path is correct from the working directory.
Audit
Dependencies
No dependency data recorded yet.