Gatsby-source-sanity plugin causing ValidationError on build

3 replies
Last updated: Jan 28, 2026
Hey all! I'm a Sanity newbie and trying to add Sanity to a Gatsby project I'm working on. I'm trying to add the gatsby-sanity-source plugin and when I try and build the project I get this gnarly error.

Failed to validate error Error [ValidationError]: child "error" fails because ["error" must be an object]

If I remove the plugin code from gatsby-config. It builds fine. The plugin objectlooks like this (I removed the projectId from this message):


{
resolve: 'gatsby-source-sanity',
options: {
projectId: 'my-id',
dataset: 'production',

// a token with read permissions is required

// if you have a private dataset

token: <http://process.env.MY|process.env.MY>_SANITY_TOKEN,

},

},

Any ideas what I'm missing?
AI Update

I can see the issue! The problem is in your token configuration. You have:

token: <http://process.env.MY|process.env.MY>_SANITY_TOKEN,

This syntax is incorrect. The token option expects a string value, but what you have there looks like it got mangled (possibly by a Slack auto-formatter turning it into a link). It should be:

token: process.env.MY_SANITY_TOKEN,

Notice there are no angle brackets, no http://, and no pipe character - just the plain environment variable reference.

Your corrected plugin configuration should look like:

{
  resolve: 'gatsby-source-sanity',
  options: {
    projectId: 'my-id',
    dataset: 'production',
    token: process.env.MY_SANITY_TOKEN,
  },
}

The validation error you're seeing ("child "error" fails because ["error" must be an object]") is Gatsby's way of saying the plugin options didn't validate correctly - in this case because the malformed token value caused the plugin initialization to fail.

A few additional tips for getting started with gatsby-source-sanity:

  • If your dataset is public, you can actually omit the token option entirely
  • For draft content preview during development, add watchMode: true and overlayDrafts: true to your options (this requires a token with read permissions). The overlayDrafts feature lets you see draft content in development while keeping only published content in production.
  • Important: You need to deploy your GraphQL API from your Sanity Studio first by running sanity graphql deploy in your studio folder. The gatsby-source-sanity plugin relies on this deployed GraphQL schema to work properly.

Once you fix that token syntax, your build should work fine!

Show original thread
3 replies

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?