Joint session with Vercel: How to build intelligent storefronts (May 15th) β†’

ReferenceError: document is not defined during Sanity GraphQL deploy

16 repliesLast updated: Nov 29, 2025

Anyone ever run into this one?
Uncaught [ReferenceError: document is not defined]
when deploying the graphql? It errors midway but still successfully deploys πŸ€” (Just ran a sanity upgrade just in case, but still persists!)
Anyone ever run into this one?  `Uncaught [ReferenceError: document is not defined]`
yarn deploy:graphql
yarn run v1.22.10
$ sanity graphql deploy --playground
Dataset: production
Tag: default

βœ” Checking for deployed API
βœ” Generating GraphQL schema
β ‹ Validating GraphQL APIError: Uncaught [ReferenceError: document is not defined]
–––––[FULL ERROR IN THREAD]–––––
βœ” Validating GraphQL API
βœ” Deploying GraphQL API
GraphQL API deployed to:
[myGraphQlPlaygroundUrlHere]
AI Update

This is a known issue that occurs when your Sanity schema contains code that references browser-specific globals like document or window, which aren't available in the Node.js environment where the GraphQL deploy command runs.

The good news is that your deployment is actually succeeding despite the error! The "βœ” Deploying GraphQL API" and "GraphQL API deployed to..." messages confirm this. The error happens during the validation step but doesn't block the actual deployment.

Common causes:

How to fix it:

The best approach is to wrap any browser-specific code in conditional checks:

// In your schema files
const MyComponent = () => {
  if (typeof document !== 'undefined') {
    // Browser-only code here
  }
}

Or use lazy loading for components:

components: {
  input: typeof document !== 'undefined' 
    ? require('./MyCustomInput').default 
    : undefined
}

Debugging steps:

sanity graphql deploy --playground --debug

Or set the environment variable:

SANITY_LOG_LEVEL=debug sanity graphql deploy

Since the deployment is working, you could technically leave it as-is, but fixing the root cause will clean up your deploy logs and prevent potential issues if Sanity changes how schema validation works in future versions.

If you're having trouble tracking down where the document reference is coming from, try temporarily removing custom components from your schema one by one until the error disappears - that'll help you isolate which file is causing it.

Show original thread
16 replies

Was this answer helpful?

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.

Related contributions