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.
defineCollection
✓ import { defineCollection } from 'pocketbase-zod-schema/schema'
✗ import { defineCollection } from 'pocketbase-zod-schema'
Must import from subpath 'pocketbase-zod-schema/schema', not the main package.
TextField, BoolField, etc.
✓ import { TextField, BoolField } from 'pocketbase-zod-schema/schema'
✗ import { TextField } from 'pocketbase-zod-schema'
Field types are exported from the same subpath. TypeScript typing relies on these.
TypedPocketBase
✓ import { TypedPocketBase } from './pocketbase-types'; // generated file
✗ import { TypedPocketBase } from 'pocketbase-zod-schema'
This type is generated by CLI; not part of the package itself. Common mistake: trying to import from package.
Defines a PocketBase collection 'posts' using Zod schema with relations. Run commands to generate migrations and TypeScript types.
// Create src/schema/post.ts
import { z } from "zod";
import { defineCollection, TextField, EditorField, BoolField, RelationField } from "pocketbase-zod-schema/schema";
export const PostSchema = z.object({
title: TextField({ min: 1, max: 200 }),
content: EditorField(),
published: BoolField(),
author: RelationField({ collection: "users" }),
});
export const PostCollection = defineCollection({
collectionName: "posts",
schema: PostSchema,
permissions: {
listRule: '@request.auth.id != ""',
viewRule: "",
createRule: '@request.auth.id != ""',
updateRule: "author = @request.auth.id",
deleteRule: "author = @request.auth.id",
},
});
// Then run: npx pocketbase-migrate generate
// and: npx pocketbase-migrate generate-types
Errors
Common errors & fixes
Cannot find module 'pocketbase-zod-schema/schema'
Missing or incorrect import path in Node.js (CJS requires specific path resolution).
fixEnsure you import from 'pocketbase-zod-schema/schema' and that package is installed.
TypedPocketBase is not exported from 'pocketbase-zod-schema'
Attempting to import TypedPocketBase directly from the package; it's generated by CLI.
fixRun 'npx pocketbase-migrate generate-types' and import from the generated file.
TypeError: defineCollection is not a function
Trying to import defineCollection from wrong path or version mismatch.
fixUse 'import { defineCollection } from "pocketbase-zod-schema/schema";'. Audit
Dependencies
zodrequiredRequired for defining schema using Zod primitives