
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can totally understand your confusion! Let me break this down into clear, practical steps for your Gatsby + Sanity + Netlify setup.
First, the good news: you don't need to choose between those two "hosting and deployment" options you're reading about. Those sections are actually about hosting Sanity Studio itself (the content editing interface), not about deploying your Gatsby site. Let me clarify what's happening:
Your Netlify build is failing because your Gatsby site needs to fetch content from Sanity during the build process, but it doesn't have the proper configuration yet. This is a common setup step that's separate from hosting decisions.
1. Install the Gatsby source plugin (if you haven't already):
npm install gatsby-source-sanity2. Configure your gatsby-config.js to connect to Sanity:
module.exports = {
plugins: [
{
resolve: 'gatsby-source-sanity',
options: {
projectId: 'your-project-id',
dataset: 'production', // or whatever dataset you're using
token: process.env.SANITY_TOKEN, // optional, for private datasets
watchMode: true, // for development
},
},
],
}3. Set up environment variables in Netlify:
SANITY_PROJECT_ID: your project ID (find it in sanity.json or your Sanity dashboard)SANITY_DATASET: usually "production"SANITY_TOKEN: only needed if your dataset is private (create one in your Sanity project settings)CI/CD means "Continuous Integration/Continuous Deployment" - it's just a fancy way of saying "automatically build and deploy when you push code to GitHub."
"Serving the bundle" refers to hosting your Sanity Studio (the content management interface where editors create content). You have two options:
sanity deploy to host it at yourproject.sanity.studioFor most people, I'd recommend option 2 (sanity deploy) because it's simpler - just run that command and your Studio is hosted. Your Gatsby site remains separate on Netlify.
@sanity/cli DependencyWhen the docs mention adding @sanity/cli as a devDependency, they mean in your Sanity Studio folder (where your sanity.json file lives), not your Gatsby repo. If you initialized Sanity properly, this should already be there.
As explained in this community answer about hosting Studio on Netlify, where you host your Studio doesn't affect API requests. The Studio is just a React single-page application - your Gatsby site will still make requests to Sanity's Content Lake regardless of where the Studio lives.
Pros of hosting Studio on Sanity's servers (sanity deploy):
Pros of hosting Studio on Netlify:
gatsby-source-sanity in your Gatsby projectgatsby-config.js with your project ID and datasetsanity deploy (run this in your Studio folder)The Netlify technology partner page has more details about triggering rebuilds when content changes, which you'll want to set up next using deploy hooks or Sanity Functions for more advanced automation!
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store