Error adding array to rich text and GraphQL deployment error

9 replies
Last updated: May 25, 2021
has anyone gotten this error when trying to add an array to rich text? It crashes the whole studio
TypeError: (value || []).some is not a function
    at ArrayInput.render (/static/js/app.bundle.js:334325:44)
    at finishClassComponent (/static/js/vendor.bundle.js:20318:31)
    at updateClassComponent (/static/js/vendor.bundle.js:20268:24)
    at beginWork (/static/js/vendor.bundle.js:21778:16)
    at HTMLUnknownElement.callCallback (/static/js/vendor.bundle.js:3346:14)
    at Object.invokeGuardedCallbackDev (/static/js/vendor.bundle.js:3395:16)
    at invokeGuardedCallback (/static/js/vendor.bundle.js:3450:31)
    at beginWork$1 (/static/js/vendor.bundle.js:26361:7)
    at performUnitOfWork (/static/js/vendor.bundle.js:25312:12)
    at workLoopSync (/static/js/vendor.bundle.js:25288:22)

AI Update

I've seen this error before! The TypeError: (value || []).some is not a function when adding an array to rich text (Portable Text) usually happens because of a schema configuration issue where your array field has corrupted data or an unexpected initial value.

Based on a community discussion about this exact error, here's what's likely happening and how to fix it:

Most Common Causes

1. Corrupted Document Data The error happens when the ArrayInput component tries to call .some() on a value that isn't actually an array. This typically occurs when you accidentally saved a document with an object {} instead of an array [] for your Portable Text field.

2. Schema Configuration Issue Sometimes an initialValue is set incorrectly:

// ❌ WRONG - will cause the error
{
  name: 'content',
  type: 'array',
  of: [{type: 'block'}],
  initialValue: {} // Object instead of array!
}

// ✅ CORRECT
{
  name: 'content',
  type: 'array',
  of: [{type: 'block'}],
  initialValue: [] // or just omit it
}

How to Fix It

Since you can't open the document in Studio to fix it, you'll need to edit it directly using the CLI:

Step 1: Get the document ID from the URL when you try to open it (even though it crashes). It'll look something like:

http://localhost:3333/desk/post;14f09fac-ddad-d4d4-9ed5-4b12346b3f90

Copy the ID part: 14f09fac-ddad-d4d4-9ed5-4b12346b3f90

Step 2: Open the document JSON in your terminal from your Studio directory:

sanity documents create --watch --replace --id 'YOUR_DOCUMENT_ID'

If you want to use VS Code as your editor:

VISUAL=code sanity documents create --watch --replace --id 'YOUR_DOCUMENT_ID'

Step 3: Look for the problematic array field in the JSON. It will likely look like:

"content": {}

Change it to:

"content": []

Step 4: Save and close the editor. The document will be updated automatically.

Important Note: If the document was published, you may also need to fix the draft version. The draft ID starts with drafts. - so if your document ID is abc123, you should also edit drafts.abc123 using the same command.

Prevention

After fixing the corrupted document, check your schema definition to ensure:

  • No initialValue is set to an object for array fields
  • Custom blocks are properly defined as object types if you're extending Portable Text
  • You're not accidentally passing objects where arrays are expected in your code

This should get your Studio back up and running! The CLI approach has helped others with this exact same error message.

and also getting this error after trying updating the studio when I try to deploy graphql 😞
   Error: Syntax Error: Expected Name, found [ at ~/web/stoneroad/sanity/node_modules/@sanity/core/lib/actions/graphql/deployApiAction.js:156:31
    at Generator.throw (<anonymous>)
    at asyncGeneratorStep (~/web/stoneroad/sanity/node_modules/@sanity/core/lib/actions/graphql/deployApiAction.js:7:103)
    at _throw (~/web/stoneroad/sanity/node_modules/@sanity/core/lib/actions/graphql/deployApiAction.js:9:291)

export default {
  name: "responsiveImages",
  type: "array",
  title: "Responsive Images",
  of: [
    {
      type: "object",
      fields: [
        { name: "image", type: "figure" },
        {
          name: "size",
          type: "string",
          options: {
            list: [
              { title: "Sci-Fi", value: "sci-fi" },
              { title: "Western", value: "western" },
            ],
            layout: "radio",
          },
        },
      ],
    },
  ],
};
trying to add that to the portable text schema
import { BsFillImageFill, BsImages } from "react-icons/Bs";

export default {
  name: "richText",
  title: "Rich text",
  type: "array",
  of: [
    {
      type: "block",
      styles: [
        { title: "Normal", value: "normal" },
        { title: "H1", value: "h1" },
        { title: "H2", value: "h2" },
      ],
      lists: [],
      marks: {
        decorators: [
          { title: "Strong", value: "strong" },
          { title: "Underline", value: "underline" },
        ],
      },
    },
    { type: "figure" },
    { type: "lineBreak" },
    { type: "images" },
  ],
};
well this example im just trying to add 'images' which is also an array of 'figure'
but now the graphql doesn't work in general after updating the studio. do you think you could help with that?
If you’re bringing
responsiveImages
into
richText
, then it appears you’d have an array in an array, which is not currently permitted . Could you try making
responsiveImages
an object containing an array instead?
ahh ok that worked! Thanks! Forgot that rich text is also an array.
Awesome!

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?