Error when creating new document type in Desk tool

5 replies
Last updated: May 26, 2022
The Desk tool crashed
An uncaught exception in the Desk tool caused the Studio to crash.
I just created a new document type, and the studio loads until I try to create a document, when I get the error above.
Code inside thread (to follow)
AI Update

Based on the error you're describing, the Desk tool crash when creating a new document typically indicates a schema configuration issue. Since you mentioned you just created a new document type, here are the most common causes and solutions:

Common Causes

1. Missing Required Properties Every document type needs at minimum a name and type property. Make sure your schema definition includes both:

defineType({
  name: 'yourDocumentType',
  type: 'document',
  // ... other properties
})

2. Invalid Field Definitions Fields within your document also need proper name and type properties. According to Sanity's schema documentation, you should always use the defineField helper:

fields: [
  defineField({
    name: 'title',
    type: 'string',
    title: 'Title'
  })
]

3. Circular References or Invalid Types If you're referencing other document types or using custom types, make sure they're properly defined and don't create circular dependencies.

4. Validation Rules Errors If you've added validation rules, syntax errors in those functions can crash the Studio:

validation: (rule) => rule.required() // Make sure this is properly formatted

Debugging Steps

  1. Check the browser console - Open your browser's developer tools and look for more specific error messages that will point to the exact line causing the issue

  2. Temporarily simplify the schema - Comment out all fields except the bare minimum to see if the document type itself is the problem:

defineType({
  name: 'yourDocumentType',
  type: 'document',
  fields: [
    defineField({
      name: 'title',
      type: 'string'
    })
  ]
})
  1. Verify your imports - Make sure you're importing defineType and defineField from the correct package:
import { defineType, defineField } from 'sanity'
  1. Check for typos - Common mistakes include misspelling property names like field vs fields, or using incorrect type names

  2. Look for JavaScript syntax errors - Missing commas, unclosed brackets, or improper function syntax in validation rules or custom components

When you share the code you mentioned, look specifically for:

  • Any unusual syntax in your field definitions
  • Custom components that might be throwing errors
  • Validation functions with improper syntax
  • Missing or extra commas/brackets

The browser console error will usually point to the exact line and property causing the crash, which will help narrow down the issue quickly!

import { PackageIcon } from '@sanity/icons'
import pluralize from 'pluralize'

export default {
  name: 'commonDescription',
  title: 'Common Description',
  type: 'document',
  icon: PackageIcon,
  fields: [
    // Title
    {
      name: 'title',
      title: 'Title',
      type: 'string',
      validation: Rule => Rule.required()
    },
    // Description
    {
      name: 'description',
      title: 'Description',
      type: 'block'
    },
    //Size Chart
    {
        name: 'sizeChart',
        title: 'Size Chart',
        type: 'block'
      },

    
  ],
  preview: {
    select: {
      title: 'title'
    },
    prepare(selection) {
      const { title } = selection
      return {
        title
      }
    }
  }
}
I’ve added the block documents, imported them all in the schema.js…what am I missing?
here is what the blocks documents look like (I copied them from the “body” block, maybe that’s a problem?)
export default {
    name: 'description',
    title: 'Description',
    type: 'array',
    of: [
      {
        lists: [
          { title: 'Bullet', value: 'bullet' },
          { title: 'Numbered', value: 'number' }
        ],
        marks: {
          annotations: [
            // Product
            {
              name: 'annotationProduct',
              type: 'annotationProduct'
            },
            // Email
            {
              name: 'annotationLinkEmail',
              type: 'annotationLinkEmail'
            },
            // Internal link
            {
              name: 'annotationLinkInternal',
              type: 'annotationLinkInternal'
            },
            // URL
            {
              name: 'annotationLinkExternal',
              type: 'annotationLinkExternal'
            }
          ],
          decorators: [
            {
              title: 'Italic',
              value: 'em'
            },
            {
              title: 'Strong',
              value: 'strong'
            }
          ]
        },
        // Inline blocks
        of: [{ type: 'blockInlineProduct' }, { type: 'blockInlineProductMarginalia' }],
        styles: [
          { title: 'Heading', value: 'h2' },
          { title: 'Quote', value: 'blockquote' }
        ],
        type: 'block'
      },
      // Custom blocks
      {
        name: 'blockImage',
        type: 'blockImage'
      },
      {
        name: 'blockProduct',
        type: 'blockProduct'
      }
    ]
  }
  
The
block
type needs to be inside an array. Can you comment out
description
and
sizeChart
to confirm the crash goes away?
perfect, I fixed it now. Thanks again!

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?