Watch a live product demo 👀 See how Sanity powers richer commerce experiences

Uncaught error - Could not resolve jsonType of undefined. No parent type found

23 replies
Last updated: Mar 18, 2021
Hi again. I have come upon another error I'm not sure about. After adding this:

marks: {
 annotations: [
  {
   name: "link",
   type: "externalLink",
   title: "Ekstern lenke",
  },
  {
   name: "internalLink",
   type: "internalLink",
   title: "Intern lenke",
  },
 ],
}
to the block type in an


of: [{ type: "block" }]
I get this error:


Uncaught error
Could not resolve jsonType of undefined. No parent type found

Stack:

    at isJSONTypeOf (<http://localhost:3333/static/js/app.bundle.js:218462:11>)
    at <http://localhost:3333/static/js/app.bundle.js:218411:55>
    at Array.map (&lt;anonymous&gt;)
    at validateAnnotations (<http://localhost:3333/static/js/app.bundle.js:218399:22>)
    at validateMarks (<http://localhost:3333/static/js/app.bundle.js:218334:19>)
    at validateBlockType (<http://localhost:3333/static/js/app.bundle.js:218291:13>)
    at visitors.reduce._objectSpread._problems (<http://localhost:3333/static/js/app.bundle.js:217140:17>)
    at Array.reduce (&lt;anonymous&gt;)
    at <http://localhost:3333/static/js/app.bundle.js:217139:21>
    at <http://localhost:3333/static/js/app.bundle.js:217161:49>

(Your browsers Developer Tools may contain more info)
I've attempted to simplify the objects in annotations, but no matter what object i feed in, the end result is the same. Only way to stop getting it is to either not feed anything into annotations, or to use an inline object. But since my current project uses gatsby, inline objects aren't an option.
Mar 17, 2021, 11:25 AM
Are both
externalLink
and
internalLink
defined in your schema?
Mar 17, 2021, 11:28 AM
Yup.
Mar 17, 2021, 11:28 AM
Tried with just one placeholder item instead of those two, and while it worked inline, it did not when used as its own type.
Mar 17, 2021, 11:29 AM
What do you mean by “When used as its own type”?
Mar 17, 2021, 11:29 AM
as in, the type: "whatever name" field 😛
Mar 17, 2021, 11:30 AM
What do your definitions look like for those types?
Mar 17, 2021, 11:30 AM
{
 name: "potet",
 type: "sopp",
 title: "haha",
}

export default {
    name: "sopp",
    type: "object",
    title: "Sopp",
    fields: [
        {
            name: "stuing",
            type: "string",
            title: "Stuing",
        },
    ],
}

Mar 17, 2021, 11:31 AM
But neither of these correspond to the types you’re trying to use?
Mar 17, 2021, 11:33 AM
externalLink
and
internalLink
Mar 17, 2021, 11:34 AM
The top one is the one I replaced those two with to simplify
Mar 17, 2021, 11:34 AM
Error from console is potentially more descriptive:
isJSONTypeOf.js:16 Uncaught Error: Could not resolve jsonType of undefined. No parent type found
at isJSONTypeOf (isJSONTypeOf.js:16)
at block.js:167
at Array.map (&lt;anonymous&gt;)
at validateAnnotations (block.js:155)
at validateMarks (block.js:90)
at validateBlockType (block.js:47)
at visitors.reduce._objectSpread._problems (validateSchema.js:62)
at Array.reduce (&lt;anonymous&gt;)
at validateSchema.js:61
at validateSchema.js:83
Mar 17, 2021, 11:35 AM
If it works inline but not when you reference it via a string, it probably means that you haven’t defined the type in your schema correctly, but I can’t say without seeing the entire schema
Mar 17, 2021, 11:36 AM
One moment
Mar 17, 2021, 11:36 AM
aploogize for mess, this is my first sanity project
// First, we must import the schema creator
import createSchema from "part:@sanity/base/schema-creator"

// Then import schema types from any plugins that might expose them
import schemaTypes from "all:part:@sanity/base/schema-type"

import siteSettings from "./siteSettings"
import frontPage from "./frontPage"
import post from "./post"
import splitRow from "./splitRow"
import linkX from "./linkX"
import openingTime from "./openingTime"
import textSection from "./textSection"
import captionedImage from "./captionedImage"
import imageTextSection from "./imageTextSection"
import card from "./card"
import cardGallery from "./cardGallery"
import altImage from "./altImage"
import popBox from "./popBox"
import page from "./page"
import internalExternalLink from "./internalExternalLink"
import aFieldWithCondition from "./aFieldWithCondition"
import conditionalInput from "./conditionalInput"
import linkOptions from "./linkOptions"
import link from "./link"
import internalLink from "./internalLink"
import externalLink from "./externalLink"
import test from "./test"
import sopp from "./sopp"

// Then we give our schema to the builder and provide the result to Sanity
export default createSchema({
    // We name our schema
    name: "default",
    // Then proceed to concatenate our document type
    // to the ones provided by any plugins that are installed
    types: schemaTypes.concat([
        /* Your types here! */
        siteSettings,
        frontPage,
        post,
        splitRow,
        linkX,
        openingTime,
        textSection,
        captionedImage,
        imageTextSection,
        card,
        cardGallery,
        altImage,
        popBox,
        page,
        internalExternalLink,
        link,
        aFieldWithCondition,
        conditionalInput,
        linkOptions,
        internalLink,
        externalLink,
        test,
        sopp,
    ]),
})
Mar 17, 2021, 11:38 AM
That looks fine, but it might help to put the files that you suspect are causing problems in a github gist or something, bit difficult to diagnose from this.
Mar 17, 2021, 11:43 AM
I can try setting up a stripped project.
Mar 17, 2021, 11:44 AM
Because I've no idea what is causing this.
Mar 17, 2021, 11:45 AM
Sure, that would likely be helpful
Mar 17, 2021, 11:49 AM
Hi Are. The way you’re handling internalLink and externalLink (as imported objects), I think you’ll want to simply name them in your portable text schema. So you could try changing this:

marks: {
 annotations: [
  {
   name: "link",
   type: "externalLink",
   title: "Ekstern lenke",
  },
  {
   name: "internalLink",
   type: "internalLink",
   title: "Intern lenke",
  },
  ...,
 ],
}
to this:


import internalLink from "./internalLink"
import externalLink from "./externalLink"

...

marks: {
 annotations: [
  externalLink,
  internalLink,
  ...,
 ],
}
Mar 17, 2021, 10:02 PM
Alternatively, you could include them inline like Knut does here , where each (i.e., internalLink and externalLink) is an inline object.
Mar 17, 2021, 10:32 PM
Importing the objects worked perfectly. So the problem here was that, in annotations as opposed to a fields array, you need to do things differently. Whereas in fields, you can reference a type that has been imported in the schema without importing it in the actual file, in annotations that is not the case. The other issue, I guess, was that the error message wasn't helpful in this instance.
Anyway, it works now, so I'm happy! Thanks for all the help, guys!
Mar 18, 2021, 5:33 AM
Great! 🙌
Mar 18, 2021, 2:28 PM
🙂
Mar 18, 2021, 2:28 PM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing