Invalid item type" error with blockContent schema in Sanity array

6 replies
Last updated: Dec 26, 2022
I am getting the non-descript error: "Error: Invalid item type: "[object Object]". Default array input can only contain objects (for now)" with this schema for this schema
/**
 * This is the schema definition for the rich text fields used for
 * for this blog studio. When you import it in schemas.js it can be
 * reused in other parts of the studio with:
 *  {
 *    name: 'someName',
 *    title: 'Some title',
 *    type: 'blockContent'
 *  }
 */
export default {
  title: 'Block Content',
  name: 'blockContent',
  type: 'array',
  of: [
    {
      title: 'Block',
      type: 'block',
      // Styles let you set what your user can mark up blocks with. These
      // correspond with HTML tags, but you can set any title or value
      // you want and decide how you want to deal with it where you want to
      // use your content.
      styles: [
        {title: 'Normal', value: 'normal'},
        {title: 'H1', value: 'h1'},
        {title: 'H2', value: 'h2'},
        {title: 'H3', value: 'h3'},
        {title: 'H4', value: 'h4'},
        {title: 'Quote', value: 'blockquote'},
      ],
      lists: [{title: 'Bullet', value: 'bullet'}],
      // Marks let you mark up inline text in the block editor.
      marks: {
        // Decorators usually describe a single property – e.g. a typographic
        // preference or highlighting by editors.
        decorators: [
          {title: 'Strong', value: 'strong'},
          {title: 'Emphasis', value: 'em'},
        ],
        // Annotations can be any object structure – e.g. a link or a footnote.
        annotations: [
          {
            title: 'URL',
            name: 'link',
            type: 'object',
            fields: [
              {
                title: 'URL',
                name: 'href',
                type: 'url',
              },
            ],
          },
        ],
      },
    },
    // You can add additional types here. Note that you can't use
    // primitive types such as 'string' and 'number' in the same array
    // as a block type.
    {
      type: 'image',
      options: {hotspot: true},
    },
  ],
}
Any thoughts on what I did wrong?
AI Update

I understand this error is frustrating! Looking at your schema, the structure actually appears correct - the image block definition {type: 'image', options: {hotspot: true}} is perfectly valid according to the image type documentation. You don't need to add a name property for items in the of array.

The "Invalid item type: '[object Object]'" error typically occurs due to schema loading or import issues rather than the schema definition itself. Here are the most likely causes:

1. Schema not properly imported/registered

The most common cause is that your blockContent schema isn't being imported correctly into your main schema configuration. Make sure you're registering it properly in your sanity.config.ts (or schema.js for older setups):

import blockContent from './blockContent'

export default defineConfig({
  // ... other config
  schema: {
    types: [blockContent, /* other types */]
  }
})

2. Schema cache issues

Sometimes the Studio caches a broken schema state. Try:

  • Stop your dev server
  • Delete the .sanity folder in your project root (if it exists)
  • Run sanity start again (or npm run dev)

3. Circular dependencies or duplicate type names

Check that:

  • You don't have another schema type also named blockContent
  • Your import paths are correct and not creating circular references

4. Using older Sanity version syntax

If you're on Sanity Studio v3+, consider using the newer defineType and defineField helpers for better type safety:

import {defineType, defineField, defineArrayMember} from 'sanity'

export default defineType({
  title: 'Block Content',
  name: 'blockContent',
  type: 'array',
  of: [
    defineArrayMember({
      title: 'Block',
      type: 'block',
      styles: [
        {title: 'Normal', value: 'normal'},
        {title: 'H1', value: 'h1'},
        {title: 'H2', value: 'h2'},
        {title: 'H3', value: 'h3'},
        {title: 'H4', value: 'h4'},
        {title: 'Quote', value: 'blockquote'},
      ],
      lists: [{title: 'Bullet', value: 'bullet'}],
      marks: {
        decorators: [
          {title: 'Strong', value: 'strong'},
          {title: 'Emphasis', value: 'em'},
        ],
        annotations: [
          {
            title: 'URL',
            name: 'link',
            type: 'object',
            fields: [
              {
                title: 'URL',
                name: 'href',
                type: 'url',
              },
            ],
          },
        ],
      },
    }),
    defineArrayMember({
      type: 'image',
      options: {hotspot: true},
    }),
  ],
})

To debug further:

Try temporarily simplifying your schema to isolate the issue:

export default {
  name: 'blockContent',
  type: 'array',
  of: [{type: 'block'}]
}

If this works, gradually add back the other configurations (styles, marks, annotations, image) one at a time to identify what's causing the problem.

The error message suggests Sanity is receiving a plain JavaScript object where it expects a properly defined type, which usually points to an import/export issue or schema registration problem rather than the schema structure itself.

Show original thread
6 replies
And the above is included in a document type for dynamic pages:
export default {
  
// Setup a 'document' type to house the page builder field

name: "locationPage",
type: "document",
title: "Location Page",
fields: 
	[
		{
			name: 'name',
			type: 'string',
			title: 'Name'
		},
		{
			name: 'cityAndState',
			type: 'string',
			title: 'City and state'
		},
		{
			name: 'href',
			type: 'string',
			title: 'HREF'
		},
		{
		name: 'pageBuilder',
		type: 'array',
		title: 'Page builder',
		of: 
			[
				{ type: 'hero' }, // hero.js (same applies for the other types)
				{ type: 'blockContent' },
				{ type: 'blockWithIllustration' },
				{ type: 'blockWithIllustrationVariable' },
				{ type: 'callToAction' },
				{ type: 'gallery' },
				{ type: 'locationWithContactOverlay' },
				{ type: 'video' },
				// etc...
			]
		}
	]
}

Is this the nested array thing that Sanity does not do/handle?
It is. At least that is what it looks like to me. So I need to convert the blockContent schema to an object with a sub field of array.
/**
 * This is the schema definition for the rich text fields used for
 * for this blog studio. When you import it in schemas.js it can be
 * reused in other parts of the studio with:
 *  {
 *    name: 'someName',
 *    title: 'Some title',
 *    type: 'blockContent'
 *  }
 */
export default {
	name: 'blockContent',
	type: 'object',
  title: 'Block Content',
	fields: [
		{
			name: 'block',
			type: 'array',
			of: [
				{
					title: 'Block',
					type: 'block',
					// Styles let you set what your user can mark up blocks with. These
					// correspond with HTML tags, but you can set any title or value
					// you want and decide how you want to deal with it where you want to
					// use your content.
					styles: [
						{title: 'Normal', value: 'normal'},
						{title: 'H1', value: 'h1'},
						{title: 'H2', value: 'h2'},
						{title: 'H3', value: 'h3'},
						{title: 'H4', value: 'h4'},
						{title: 'Quote', value: 'blockquote'},
					],
					lists: [{title: 'Bullet', value: 'bullet'}],
					// Marks let you mark up inline text in the block editor.
					marks: {
						// Decorators usually describe a single property – e.g. a typographic
						// preference or highlighting by editors.
						decorators: [
							{title: 'Strong', value: 'strong'},
							{title: 'Emphasis', value: 'em'},
						],
						// Annotations can be any object structure – e.g. a link or a footnote.
						annotations: [
							{
								title: 'URL',
								name: 'link',
								type: 'object',
								fields: [
									{
										title: 'URL',
										name: 'href',
										type: 'url',
									},
								],
							},
						],
					},
				},
				// You can add additional types here. Note that you can't use
				// primitive types such as 'string' and 'number' in the same array
				// as a block type.
				{
					type: 'image',
					options: {hotspot: true},
				},
			],
		}
	],
}

So I had to wrap the array in an object basically.
Hello
user A
👋Yes so for now arrays cannot be pasted into arrays directly (
blockContent
is an array, so pasting it directly into an array will throw the error).
More here

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?