Deploying with Netlify - Localhost Gives 404
Based on your description, it sounds like you're experiencing a 404 error when running your Sanity Studio locally, and you've identified that it works when you switch to a different project ID. Here are some steps to troubleshoot this issue:
Check Your Project ID Configuration
Since changing the projectId to another project makes it work, the issue is likely related to how your current project ID is configured. Here's what to verify:
1. Confirm your Project ID is correct
Double-check that the projectId in your sanity.config.js file matches your actual Sanity project. You can find your correct Project ID in:
- The Sanity management dashboard at sanity.io/manage
- Your project settings in the Sanity interface
2. Check your configuration file
Make sure your sanity.config.js has the correct projectId:
import { defineConfig } from 'sanity'
export default defineConfig({
projectId: 'your-actual-project-id', // Make sure this matches your project
dataset: 'production', // or 'development'
// ... rest of your config
})3. Verify environment variables
If you're using environment variables, ensure they're properly set up. Remember that Studio environment variables must be prefixed with SANITY_STUDIO_:
# .env.development
SANITY_STUDIO_API_PROJECT_ID=your-project-id
SANITY_STUDIO_API_DATASET=productionThen reference them in your config:
export default defineConfig({
projectId: process.env.SANITY_STUDIO_API_PROJECT_ID,
dataset: process.env.SANITY_STUDIO_API_DATASET,
})Common Issues to Check
Dataset permissions: The project ID might be correct, but if your dataset doesn't exist or you don't have access to it, you'll get errors. Verify that:
- The dataset name in your config matches an actual dataset in your project
- You have the necessary permissions for that dataset
Authentication: Make sure you're logged into the correct Sanity account locally. Try running:
sanity logout
sanity loginClear cache and reinstall: Sometimes configuration issues can be resolved by clearing your cache:
rm -rf node_modules
npm installSince your Studio works fine on Netlify but fails locally with a 404, and switching to another project ID makes it work, the most likely culprit is either a typo in the project ID or a mismatch between your local configuration and what's deployed. Remember that project IDs are not secret information, so you can safely check them in your deployed code to compare with your local setup.
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.