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.
Papr
✓ import Papr, { schema, types } from 'papr';
✗ const Papr = require('papr').default;
Papr exports a default class and named exports. In CommonJS, destructure correctly: const { default: Papr, schema, types } = require('papr');
schema
✓ import { schema } from 'papr';
✗ const schema = require('papr').schema;
schema is a named export, not a default export. Ensure destructuring in CommonJS.
types
✓ import { types } from 'papr';
✗ const types = require('papr/types');
types is a named export from the main entry, not a separate module. Do NOT import from 'papr/types' — that path does not exist.
Defines a Papr model with typed schema using papr's schema and types, then queries documents.
import Papr, { schema, types } from 'papr';
const papr = new Papr();
const User = papr.model('users', schema({
age: types.number(),
firstName: types.string({ required: true }),
lastName: types.string({ required: true }),
}));
const johnWick = await User.find({ firstName: 'John', lastName: 'Wick' });
console.log(johnWick);
Debug
Known issues
breakingPapr v17 requires Node.js >=22.12.0 and mongodb driver ^7.0.0. Older Node.js versions will cause runtime errors.fixUpgrade Node.js to >=22.12.0 and mongodb to ^7.0.0.
affects: >=17.0.0
gotchaMongoDB JSON Schema validation requires MongoDB 3.6+. Using papr with older MongoDB versions will silently skip validation.fixEnsure your MongoDB server is 3.6 or later. If using an older version, consider upgrading or adding application-level validation.
affects: all
gotchaPapr does not create indexes or collections automatically. You must create them beforehand for schema validation to apply.fixUse MongoDB's createCollection with validator option, or use papr's syncIndexes if available.
affects: all
deprecatedIn papr v16, the 'types' export was restructured. Some type helpers like types.array were removed.fixUse types.array() (re-introduced) or define arrays via schema({ field: types.array(types.string()) }) affects: >=16.0.0 <17.0.0
breakingPapr v15 dropped support for callback-based operations. All database methods now return Promises only.fixReplace callbacks with async/await or .then() chains.
affects: >=15.0.0
Errors
Common errors & fixes
Error: Cannot find module 'papr'
Package not installed or incorrect import path.
fixRun: npm install papr@17.1.0
TypeError: papr.model is not a function
Incorrect import; using CommonJS without destructuring the default export.
fixUse const { default: Papr, schema, types } = require('papr'); then instantiate: new Papr() Error: The "types" object is not iterable
Attempting to import types from 'papr/types' subpath instead of the main export.
fixChange import to: import { types } from 'papr'; MongoError: Document failed validation
Document does not conform to the JSON Schema defined on the collection.
fixCheck that you have created the collection with a validator containing the schema generated by papr. Ensure all required fields are present.
Audit
Dependencies
mongodbrequiredPeer dependency; papr wraps the MongoDB Node.js driver and requires it for database operations.