Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Error when using internalLink annotation in Sanity Studio

4 replies
Last updated: Apr 20, 2021
Hi, I am trying to add internalLink annotation to block content, but after I create a separate type internalLink and use it in the annotation tag via:
annotations: [{ type: 'internalLink' }]
studio trow me error:
Uncaught error
Could not resolve jsonType of undefined. No parent type found

Stack:

    at isJSONTypeOf (<http://localhost:3333/studio/static/js/app.bundle.js:231611:11>)
    at <http://localhost:3333/studio/static/js/app.bundle.js:231560:55>
    at Array.map (<anonymous>)
    at validateAnnotations (<http://localhost:3333/studio/static/js/app.bundle.js:231548:22>)
    at validateMarks (<http://localhost:3333/studio/static/js/app.bundle.js:231483:19>)
    at validateBlockType (<http://localhost:3333/studio/static/js/app.bundle.js:231440:13>)
    at visitors.reduce._objectSpread._problems (<http://localhost:3333/studio/static/js/app.bundle.js:230289:17>)
    at Array.reduce (<anonymous>)
    at <http://localhost:3333/studio/static/js/app.bundle.js:230288:21>
    at <http://localhost:3333/studio/static/js/app.bundle.js:230310:49>

(Your browsers Developer Tools may contain more info)
internalLink definitions:

import React from 'react';

const InternalLinkRender = ({ children }) => <span>{children} 🔗</span>;

export default {
  title: 'Internal link to another document',
  name: 'internalLink',
  type: 'reference',
  description: 'Locate a document you want to link to',
  to: [{ type: 'page' }, { type: 'route' }],
  blockEditor: {
    icon: () => '🔗',
    render: InternalLinkRender,
  },
};
In browser console I have this errortrace:

Uncaught Error: Could not resolve jsonType of undefined. No parent type found
    at isJSONTypeOf (isJSONTypeOf.js:16)
    at block.js:167
    at Array.map (<anonymous>)
    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 (<anonymous>)
    at validateSchema.js:61
    at validateSchema.js:83
Apr 16, 2021, 12:32 PM
Can you try replacing
annotations: [{ type: 'internalLink' }]
with
annotations: [internalLink]
, then making sure you’re importing
internalLink
.
Apr 16, 2021, 2:32 PM
user A
ok this works, if I import internalLink direct to document where I use it. But I thought it was enough to add it to the schemas.js as a new type.
Apr 16, 2021, 3:17 PM
In your
schema.js
did you both import
internalLink
and add it to the types array?
Apr 16, 2021, 5:30 PM
user M
yes, like many other types. It work if I use it non as annotation but as field in this document, but in the annotation it trwos this error. If I import it directly to document and use it this way, I have problem with resolve reference in the GraphQL qeury.
Apr 20, 2021, 7:04 AM

Sanity– build remarkable experiences at scale

Sanity is a modern 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?