Upgrading dependencies causes error in schema, resolved by fixing load order

17 replies
Last updated: Jun 14, 2022
I’m working to upgrade the dependencies for our studio and hitting the below error. Any tips on how to figure out root cause, because nothing has changed. I’d rather not do a manual binary search through out schemas 😬

Uncaught Error: Could not resolve jsonType of undefined. No parent type found
    at isJSONTypeOf (isJSONTypeOf.js:16:1)
    at block.js:167:1
    at Array.map (<anonymous>)
    at validateAnnotations (block.js:155:1)
    at validateMarks (block.js:90:1)
    at validateBlockType (block.js:47:1)
    at visitors.reduce._objectSpread._problems (validateSchema.js:65:1)
    at Array.reduce (<anonymous>)
    at validateSchema.js:64:1
    at validateSchema.js:86:1
Jun 13, 2022, 10:50 PM
This error usually comes up when a schema is missing a name key. Is that possible here?
Jun 13, 2022, 10:51 PM
It was working prior to the upgrade… so maybe? That’s a good lead for me to follow
Jun 13, 2022, 10:52 PM
Binary searching finds one schema that has an array of `block`s and it’s the
marks.annotations
that’s breaking things. All of them are of type
object
, and otherwise look fine.
Jun 13, 2022, 11:09 PM
What do your annotations look like on your block type?
Jun 13, 2022, 11:15 PM
I’m starting to wonder if its related to the load order of the schema files. Do you know if anything changed there? We also have a problem where there may be dependency cycles between types through
references
.
Jun 13, 2022, 11:18 PM
Here’s an example annotation:

export default {
  name: 'emailLink',
  title: 'Email Link',
  type: 'object',
  icon: AiOutlineMail,
  fields: [
    {
      name: 'email',
      title: 'Email address',
      description: '',
      type: 'string',
      validation: Rule =>
        Rule.custom(field => {
          if (field === undefined) return 'URL must be set';
          if (!EMAIL_TEST.test(field)) return 'Invalid Email address format';
          return true;
        })
    },
    {
      name: 'subject',
      title: 'Subject',
      description: 'Optional subject line of the email',
      type: 'string'
    }
  ]
};
Jun 13, 2022, 11:19 PM
Thanks! I'll see if I can track this down. What version were you previously on before trying to upgrade?
Jun 13, 2022, 11:20 PM
thank you for the help. We were at Sanity base 2.3.6 and now moving to 2.30.1
Jun 13, 2022, 11:21 PM
Oh, do you mind sharing the entirety of your block content schema?
Jun 13, 2022, 11:25 PM
export default {
  name: 'articleBody',
  title: 'Body',
  type: 'array',
  of: [
    {
      type: 'block',
      styles: [
        { title: 'Normal', value: 'normal' },
        { title: 'H2', value: 'h2' },
        { title: 'H3', value: 'h3' },
        { title: 'Quote', value: 'blockquote' }
      ],
      lists: [
        { title: 'Bullet', value: 'bullet' },
        { title: 'Numbered', value: 'number' }
      ],
      marks: {
        // Only allow these decorators
        decorators: [
          { title: 'Strong', value: 'strong' },
          { title: 'Emphasis', value: 'em' },
          { title: 'Code', value: 'code' },
          {
            title: 'Center',
            value: 'center',
            blockEditor: {
              icon: () => <FiAlignCenter />,
              render: centerRenderer
            }
          }
        ],
        annotations: [
          //{ type: 'internalLink' },
          //{ type: 'externalLink' },
          //{ type: 'emailLink' },
          //{ type: 'quickstartLink' }
        ]
      }
    }
  ]
};
Jun 13, 2022, 11:25 PM
With the annotations commented out, I don’t get the above error.
Jun 13, 2022, 11:26 PM
(I get another error, but one bridge at a time 🙂
Jun 13, 2022, 11:26 PM
If you comment one annotation out at a time, are you able to see if it's a particular annotation? Or do they all throw an error?
Jun 13, 2022, 11:32 PM
uncommenting any single one causes the error
Jun 13, 2022, 11:33 PM
Thanks for confirming! It'll take me a bit to replicate this. I'll likely be able to follow up tomorrow!
Jun 13, 2022, 11:35 PM
Ok, I think I’ve confirmed that it is load order. We were using
import * as blocks from './blocks';
and mapping to an array automatically. By hard coding the
createSchema
call I’ve fixed the original error.
Thanks
user M
for the moral support 🙂
Jun 13, 2022, 11:49 PM
Happy yo be your :rubberduck: !
Jun 14, 2022, 12:02 AM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?

Categorized in