Deploying with Netlify - Localhost Gives 404

7 replies
Last updated: Jul 12, 2022
Hi everyone, I have a sanity studio and web deployed in my Netlify, however, when I run localhost I get a 404 any suggestions? I believe the issue is around the
projectId
key, because when I change the key to another sanity project it works and reads that one.
AI Update

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=production

Then 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 login

Clear cache and reinstall: Sometimes configuration issues can be resolved by clearing your cache:

rm -rf node_modules
npm install

Since 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.

also when i run
sanity debug
I get

Project config (sanity.cli.js):
  { error: 'Missing required "api.projectId" key' }
although the projectId is set in the file and sanity.json
Hey
user M
! Is it possible that you've put the wrong project id in?
Hi RD, thanks for the reply! I don't believe thats the case, I've check that multiple times. I've even ran a
sanity init
with the 2.30 cli to run a reconfigure the
sanity.json
Strange! And to be clear, the deployed version works but it doesn't work locally?
unfortunately both do not, localhost also runs into a 404 as well. However, when I switch to my other project (as in changing the project id in the client) it works and runs the other project, so kind of stumped here
ah, got it. Do you mind sending me the project ID that's not working so I can check our backend?
Thanks, I've DM!

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?