TypeError: Cannot Read Properties of Null (Reading 'jsonType')

4 replies
Last updated: Sep 28, 2022
Hey guys! I wrote out my schemas but im still having this error appear
TypeError: Cannot read properties of null (reading 'jsonType')
    at validateNonObjectFieldsProp (/static/js/app.bundle.js:185357:16)
    at _default (/static/js/app.bundle.js:185325:155)
    at visitors.reduce._objectSpread._problems (/static/js/app.bundle.js:183832:17)
    at Array.reduce ()
    at /static/js/app.bundle.js:183831:21
    at /static/js/app.bundle.js:183850:70
    at /static/js/app.bundle.js:183966:12
    at /static/js/app.bundle.js:183981:95
    at Array.forEach ()
    at traverseSchema (/static/js/app.bundle.js:183980:9)
any suggestions?
AI Update

This error typically happens when you have a schema field definition that's missing required properties or has a null/undefined value where Sanity expects a valid field configuration. The validateNonObjectFieldsProp function is trying to read the jsonType property from something that doesn't exist.

Here are the most common causes and how to fix them:

1. Missing type property

The most frequent cause is forgetting to include the type property in a field definition:

// ❌ This will cause the error
defineField({
  name: 'title',
  // missing type!
})

// ✅ This is correct
defineField({
  name: 'title',
  type: 'string'
})

2. Null/undefined field in fields array

Check if you have any conditional logic that might be adding null or undefined to your fields array:

// ❌ This can cause issues
fields: [
  defineField({ name: 'title', type: 'string' }),
  someCondition && defineField({ name: 'optional', type: 'string' }), // might be false
]

// ✅ Filter out falsy values
fields: [
  defineField({ name: 'title', type: 'string' }),
  someCondition && defineField({ name: 'optional', type: 'string' }),
].filter(Boolean)

3. Incorrect field reference or typo

Make sure all custom types you reference actually exist:

// ❌ If 'customType' doesn't exist in your schema
defineField({
  name: 'myField',
  type: 'customType' // typo or not defined
})

4. Using deprecated syntax

If you're on Sanity Studio v3+, make sure you're using the modern schema syntax with defineField and defineType:

import { defineField, defineType } from 'sanity'

export default defineType({
  name: 'post',
  type: 'document',
  fields: [
    defineField({
      name: 'title',
      type: 'string'
    })
  ]
})

How to debug this

  1. Check your schema files systematically - Go through each schema file and verify every field has both name and type properties
  2. Look for dynamic field generation - If you're programmatically creating fields, add console.logs to see what's being generated
  3. Use the schema validation command - Run sanity schema extract in your terminal to see if it can identify which schema has the issue
  4. Check your imports - Make sure all imported schema types are properly exported and not undefined

The stack trace shows this is happening during schema traversal, so Sanity is trying to validate your schema structure when the Studio loads. The error means it encountered a field definition that doesn't have the expected structure, most commonly because the type property is missing or the entire field definition is null/undefined.

This usually happens if you leave a
type
property off of a schema!
It seems to be a different cause, all my schemas have types and I'm searching for spelling errors, anything else you could possibly think off?
fount the error for type, document was just spelt as docunent, everything is working fine now thank you!
Fantastic!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?