ObjectStackObjectStack

Troubleshooting — common errors and fixes

Solutions to common ObjectStack issues — validation failures, query problems, configuration mistakes, and more

Solutions to the most common issues encountered when working with ObjectStack.


Installation Issues

"Cannot read properties of null (reading 'edgesOut')" from npm install

Symptom: npm exits 1 with npm error Cannot read properties of null (reading 'edgesOut') while installing @objectstack/cli or @objectstack/plugin-auth.

Cause: npm 10, the npm that Node 22 ships, crashed this way while the newest vitest 4, 4.1.12, had no matching @vitest/browser-webdriverio release: npm 10 reached vitest through an optional vitest peer in the auth library's dependency tree, or through your project's own vitest. @vitest/browser-webdriverio 4.1.12 is now published, and npm 10.9.9 installs @objectstack/cli and @objectstack/plugin-auth again (measured on 18.2.0, globally and into a project). npm 11 and pnpm were never affected, nor was npm ci from a committed lockfile.

Fix, if you still hit it (either one):

  1. Use npm 11 (it needs Node 22.9+): run npm install -g npm@11, then repeat the install. This is the only fix for npm install -g, because a global install reads no overrides. In a Dockerfile, install under a pinned npm 11, as the self-built runtime recipe does.

  2. Stay on npm 10 and pin vitest in your project's root package.json. The override puts every vitest in the tree, optional peers included, on one range, and npm 10 installs it. Then run npm install again and commit the lockfile:

    package.json
    "overrides": { "vitest": "~4.1.12" }

    If devDependencies lists vitest, set it to the same ~4.1.12: npm refuses an override that differs from a direct dependency (EOVERRIDE). A project created by npm create objectstack, os init or os create plugin already has this block. If yours reads ~4.0.0, an earlier scaffold's value, change both to ~4.1.12: ~4.0.0 installs vitest 4.0.18, which is affected by security advisory GHSA-qxg6-89mg-rqv8.


Validation Errors

"Invalid enum value" for field type

Symptom: Zod validation fails with Invalid option: expected one of "text"|"number"|...

Cause: The type value has a typo or uses an unsupported type name.

Fix: Use exact type names from the Field Type Gallery. Common mistakes:

❌ Wrong✅ Correct
text_areatextarea
multi_selectmultiselect
check_boxescheckboxes
master-detailmaster_detail
auto_numberautonumber
rich_textrichtext
qr_codeqrcode

The custom error map provides "Did you mean?" suggestions for common typos.


"Field name must be snake_case"

Symptom: Validation fails with a regex error on the name field.

Cause: Field and object names must match the pattern ^[a-z_][a-z0-9_]*$.

Fix:

❌ Wrong✅ Correct
firstNamefirst_name
Order-Itemorder_item
2ndAddresssecond_address
STATUSstatus

"A select field needs its choices"

Symptom: A select or radio field is refused at parse (on save, publish, os validate or os build), with the issue on its options path.

Cause: A single-choice field needs an option source: a non-empty options array, or a picklist naming a shared list. With neither — and options: [] counts as neither — the form control would offer nothing and server-side value validation would be off, so any value would write through. multiselect, tags and checkboxes may omit both (the first two are free-form without options; checkboxes draws a completeness warning).

Fix:

// ❌ No option source
{ name: 'status', type: 'select' }

// ✅ With options
{
  name: 'status', type: 'select',
  options: [
    { label: 'Open', value: 'open' },
    { label: 'Closed', value: 'closed' }
  ]
}

// ✅ Or with a shared list
{ name: 'industry', type: 'select', picklist: 'industry' }

A row stored before this check keeps its bytes: it is still served, with _diagnostics naming the field, listed by /meta/diagnostics, and named at boot by the field/choice-without-options log line. A later save of its object is refused until an option or a picklist is added.


"Required property missing: reference"

Symptom: A lookup or master_detail field fails validation.

Cause: Relational fields require a reference property pointing to the target object.

Fix:

// ❌ Missing reference
{ name: 'owner', type: 'lookup' }

// ✅ With reference
{ name: 'owner', type: 'lookup', reference: 'user' }

Query Issues

"My query returns empty results"

Possible causes:

  1. Wrong object name — Object names are snake_case (project_task, not ProjectTask)
  2. Filter typo — Check operator spelling ($contains, not $contain)
  3. Type mismatch — Comparing string to number or vice versa
  4. Null handling — Use $null: true instead of $eq: null

Debug steps:

// 1. Start with the simplest query
{ object: 'task', limit: 5 }

// 2. Add fields
{ object: 'task', fields: ['id', 'title', 'status'], limit: 5 }

// 3. Add one filter at a time
{ object: 'task', where: { status: { $eq: 'open' } }, limit: 5 }

"Invalid filter operator"

Symptom: Query fails with invalid_filter error code.

Fix: Check the operator name. Valid operators:

$eq, $ne, $gt, $gte, $lt, $lte,
$in, $nin, $between,
$contains, $notContains, $startsWith, $endsWith, $icontains,
$like, $ilike,
$null, $exists,
$and, $or, $not

Common mistakes:

❌ Wrong✅ Correct
$equal$eq
$notEqual$ne
$greaterThan$gt
$isNull$null
$notIn$nin
$regex$icontains

$like is not a misspelling of $contains — the two mean different things, and picking the wrong one gives a silently wrong answer rather than an error:

  • $contains takes text, matched literally as a substring. A % or _ in the comparand is an ordinary character.
  • $like takes a pattern, matched against the whole value, with the wildcards you write: % is any sequence, _ is exactly one character, and a backslash escapes either. A pattern with no wildcards is an exact comparison, not a substring search.

$ilike is $like's case-insensitive twin, and $icontains is $contains's. Both fold ASCII case only, so café does not match CAFÉ.

$like / $ilike are executed by the SQL family (driver-sql, driver-sqlite-wasm, driver-turso). The other backends refuse them with this same invalid_filter error — write $contains there.


"Sort field not found or not sortable"

Symptom: Query fails with invalid_sort error.

Fix:

  1. Verify the field exists on the object
  2. Check that the field has sortable: true (or is not explicitly set to sortable: false)
  3. Computed fields (formula, summary) may not be sortable

Configuration Issues

"Object not found" after defining it

Possible causes:

  1. Name mismatch — The object name in your query does not match the name in the definition
  2. Not registered — The object is defined but not included in defineStack({ objects: [...] })
  3. Case sensitivity — Object names are exact-match snake_case

Fix:

// Ensure the object is included in the stack (array format)
export default defineStack({
  objects: [
    { name: 'project_task', /* ... */ }
  ]
});

// Or use map format (key becomes the name)
export default defineStack({
  objects: {
    project_task: { /* ... */ }
  }
});

// Use the exact same name when querying
client.data.find('project_task', { /* query */ });

"Cannot delete record: delete restricted"

Cause: The record has dependent child records via a lookup or master_detail field, and that field resolves to restrict. Two routes get there:

  1. The field declares deleteBehavior: 'restrict'.
  2. The field is a required: true lookup whose behavior is set_null. A required foreign key cannot be cleared, so set_null is escalated to restrict — including when set_null is written out explicitly. On a multiple: true required lookup the escalation is judged per referencing row, because set_null removes only the deleted member there: rows that keep another member are updated, and the delete is refused only over the rows the removal would leave EMPTY (dependentCount counts just those). Check the refusal's developerMessage: the escalated route says (<field> is required, so it cannot be cleared).

Fix:

  1. Delete or reassign the dependent records first
  2. Change deleteBehavior to 'cascade' (deletes children), or make the child's reference optional and use 'set_null' (clears reference)
// Option A: Cascade delete (children are deleted with parent)
{ name: 'project', type: 'master_detail', reference: 'project', deleteBehavior: 'cascade' }

// Option B: Set null (children keep existing, reference cleared).
// The field must NOT be required — on a required lookup `set_null` is
// escalated to `restrict` and writing it explicitly changes nothing.
{ name: 'project', type: 'lookup', reference: 'project', deleteBehavior: 'set_null' }

On a multiple: true lookup, set_null clears only the member that was deleted — the child's other references survive — and on an optional field a set emptied that way is stored as null, the same as one never set (the multiple doc block in packages/spec/src/data/field.zod.ts, rendered in the Field reference). A row stored before that rule can still hold [], so a cleanup query or client branch that finds cleared references uses the is_empty filter ($empty: true), which matches both, rather than testing for null or for an empty array alone.


"defineStack() validation errors"

Symptom: defineStack() in strict mode reports cross-reference errors.

Fix: In strict mode, all references must be valid:

// ❌ View references non-existent object
defineStack({
  objects: [{ name: 'task', /* ... */ }],
  views: [{ list: { type: 'grid', data: { provider: 'object', object: 'contact' }, columns: ['name'] } }]  // 'contact' not defined!
});

// ✅ All references resolve
defineStack({
  objects: [
    { name: 'task', /* ... */ },
    { name: 'contact', /* ... */ }
  ],
  views: [{ list: { type: 'grid', data: { provider: 'object', object: 'contact' }, columns: ['name'] } }]
});

TypeScript Issues

"Type is not assignable"

Cause: Using a raw object literal where a parsed type is expected, or mixing up input vs. output types.

Fix: Use the define* helpers which parse and return the correct types:

// ❌ Raw object — no type checking
const view = { list: { type: 'grid', columns: ['subject', 'status'] } };

// ✅ Parsed with type checking
import { defineView } from '@objectstack/spec';
const view = defineView({
  list: {
    type: 'grid',
    data: { provider: 'object', object: 'task' },
    columns: ['subject', 'status', 'priority'],
  },
});

"Property does not exist on type"

Cause: Accessing a property that exists on the Zod schema but not on the inferred TypeScript type (usually optional properties that were not provided).

Fix: Use optional chaining or check for undefined:

const field = FieldSchema.parse(data);

// ❌ May be undefined
console.log(field.maxLength.toString());

// ✅ Safe access
console.log(field.maxLength?.toString() ?? 'no limit');

Performance Issues

"Query is slow"

Checklist:

  1. Add indexes — Declare indexes in the object's indexes[] array (e.g. indexes: [{ fields: ['status'] }]) for fields used in where clauses — there is no field-level index flag
  2. Limit fields — Only request fields you need (fields: ['id', 'name'])
  3. Use pagination — Always set limit to avoid returning all records
  4. Avoid deep nesting — Limit nested $and/$or depth
  5. Use keyset pagination — For large datasets, seeking past the last row is faster than a deep offset. Express the keyset as a where predicate on the sort key (the cursor query property was removed in @objectstack/spec 17, #4286 — nothing ever read it)
// Optimized query — next page seeks past the last row instead of offsetting
{
  object: 'activity',
  fields: ['id', 'type', 'created_at'],                    // Only needed fields
  where: {
    type: { $eq: 'login' },                                // On indexed field
    created_at: { $lt: lastSeenCreatedAt },                // Keyset: past the last row
  },
  orderBy: [{ field: 'created_at', order: 'desc' }],
  limit: 25,
}

"Bundle size is too large"

Cause: @objectstack/spec does not re-export domain schemas (like FieldSchema or QuerySchema) from its root — only define* factory functions and a handful of top-level schemas are available there. Each domain (~400 Zod schema closures total) is only reachable through its subpath, so an import that assumes it's on the root will not resolve.

Fix: Import from subpaths instead of the root:

// ❌ Not exported from the root at all
import { FieldSchema, QuerySchema } from '@objectstack/spec';

// ✅ Tree-shakeable subpath imports
import { FieldSchema } from '@objectstack/spec/data';
import { ErrorResponseSchema } from '@objectstack/spec/api';

Available subpaths (the ./* entries of the package's exports map, in its order): data, system, kernel, ai, automation, api, api-assembled, ui, contracts, integration, security, studio, marketplace, qa, identity, shared, meta-spelling, migrations.


FAQ

What Node.js version is required?

Node.js 22.0.0 or later. The engines field in package.json enforces this.

TypeScript 5.3.0 or later for full type inference support.

How do I validate data at runtime?

Use Zod's .parse() or .safeParse() methods:

import { FieldSchema } from '@objectstack/spec/data';

// Throws on invalid data
const field = FieldSchema.parse(input);

// Returns result object (no throw)
const result = FieldSchema.safeParse(input);
if (result.success) {
  console.log(result.data);
} else {
  console.error(result.error);
}

How do I get better error messages?

Use the built-in safeParsePretty() helper:

import { safeParsePretty } from '@objectstack/spec';

const result = safeParsePretty(FieldSchema, input);
// Pretty-printed errors with "Did you mean?" suggestions

Can I use ObjectStack with JavaScript (not TypeScript)?

Yes. All schemas work with plain JavaScript. You lose compile-time type checking but retain runtime validation via Zod's .parse().

How do I extend a built-in schema?

It depends on whether the schema you are extending carries a parse-time .transform(). A plain schema (FieldSchema, ObjectSchema since protocol 17 retired their alias-lowering transforms, #3855) is a ZodObject and takes .extend() directly. The composition form works in either case, and is the safe default when you don't want to track which is which:

import { z } from 'zod';
import { FieldSchema } from '@objectstack/spec/data';

// Plain object schema: .extend() works directly. (This line is what pins the
// claim — if FieldSchema ever grows a transform again and becomes a ZodPipe,
// .extend vanishes and this example fails CI instead of the prose going stale.)
const CustomFieldSchema = FieldSchema.extend({
  customProperty: z.string().optional(),
});
CustomFieldSchema.parse({ name: 'code', type: 'text', customProperty: 'x' });

// Composition: parse with the built-in schema, validate additions alongside.
// Shape-agnostic — works for plain schemas AND transform-carrying pipes.
const CustomProps = z.object({ customProperty: z.string().optional() });
function parseCustomField(input: unknown) {
  return { ...FieldSchema.parse(input), ...CustomProps.parse(input) };
}
parseCustomField({ name: 'code', type: 'text', customProperty: 'x' });

A schema that still lowers author-facing sugar at parse time — ActionSchema (its requiresFeature → visible lowering) is one, as of protocol 17 — is a ZodPipe, where .extend does not exist: prefer the composition form. Reaching the inner object via .in.extend({ … }) builds a merged schema but skips the transform, so the sugar the pipe would have lowered stays raw.

A quick check when unsure: typeof SomeSchema.extend === 'function' — a pipe reports undefined. This page once asserted the shapes the other way around; the schemas moved under it within days (#3890 → #3855), which is why the load-bearing claim above now lives in a CI-checked block rather than prose.

Where are the JSON Schemas for IDE autocomplete?

The bundled JSON Schema is at packages/spec/json-schema/objectstack.json (its x-schema-count field reports the total number of definitions). Per-domain schemas are in subfolders under packages/spec/json-schema/ (e.g. data/, ui/, api/).

On this page