
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeHey there! Sorry to hear you're running into deployment issues with the Sanity Gatsby blog starter on Netlify. This is actually a pretty common stumbling block, especially since the starter uses a monorepo structure with both the Gatsby site and Sanity Studio in the same repository. Let me walk you through what's likely happening and how to fix it.
The sanity-gatsby blog starter has two main folders:
web/ - your Gatsby frontendstudio/ - your Sanity StudioWhen Netlify tries to build, it needs to know which folder to build from and where to find the built files. If these aren't configured correctly, you'll get that "non-zero exit code: 2" error.
You need to set two key settings in Netlify:
webweb/publicHere's how to fix it:
webweb/publicnpm run build (if not already set)Add a netlify.toml file to the root of your repository with this configuration:
[build] base = "web" publish = "web/public" command = "npm run build"
The Gatsby site needs to connect to your Sanity project. Make sure you've added these environment variables in Netlify (under Site settings → Environment variables):
SANITY_PROJECT_ID - Your project IDSANITY_DATASET - Usually productionSANITY_TOKEN - If you're using private datasetsYou can find your project ID in your Sanity project dashboard or in studio/sanity.json.
If you're still getting errors after setting the base directory:
web/ foldergatsby-config.js with your project ID and dataset.env.production: Make sure you have this file in your web/ folder with your Sanity credentials (though environment variables in Netlify are preferred)The guide on deploying Sanity Studio to Netlify in a monorepo has more details if you're also trying to deploy the Studio separately.
webweb/publicnpm run buildTry these settings and redeploy. The build should complete successfully! If you're still stuck, share the specific error from your Netlify build log and we can dig deeper. Good luck! 🚀
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