Discussion on deploying a portfolio built with Sanity and Gatsby to Netlify, including resolving errors related to url mismatch, image references, and invalid file names.

30 replies
Last updated: Jun 22, 2021
Hello everyone! I have been building my portfolio with Sanity and Gatsby. I tried to deploy it to Netlify but the front-end keeps failing - I dont know why. I remember that when i first created the project the github repository slug an extra space which was interpreted into a dash ” - ” so I modified the url on github and on Netlify but I can’t modify it on Sanity studio as I am assuming this might be the issue.Does anyone know how to deploy the front-end to Netlify or manually edit the project info?
AI Update

I understand your frustration with the Netlify deployment! The good news is that the project info displayed in your Sanity Studio dashboard (like the repository slug) is just for convenience and shouldn't affect your actual deployment. Let me help you troubleshoot both issues.

About the Dashboard Project Info

The project info widget in Sanity Studio is purely informational - it displays metadata about your project but doesn't control how your site deploys. If you used one of Sanity's starter templates that includes a dashboardConfig.js file (common in older Sanity v2 projects), this is where that repository information is stored.

If you want to update it for consistency, you can:

  1. Look for a dashboardConfig.js file in your studio folder (usually in the root or a config directory)
  2. Find the projectInfoWidget configuration and update the repository slug to match your new GitHub URL
  3. The configuration typically looks something like this:
{
  name: 'project-info',
  options: {
    data: [
      {
        title: 'GitHub repo',
        value: 'your-username/your-repo-name',
        category: 'Code'
      }
    ]
  }
}

However, this won't fix your deployment issue - it's just cosmetic.

Troubleshooting Your Netlify Deployment

The real issue is your frontend build failing on Netlify. Here are the most common causes with Gatsby + Sanity deployments:

1. Environment Variables Missing Make sure you've added your Sanity project ID and dataset name to Netlify's environment variables:

  • Go to Site settings → Environment variables in Netlify
  • Add SANITY_PROJECT_ID and SANITY_DATASET (usually "production")
  • Add SANITY_TOKEN if your content requires authentication

2. Build Command Issues

  • Check that your build command in Netlify is correct (usually gatsby build or npm run build)
  • Verify your Node version - Gatsby may require a specific version. You can set this with a .nvmrc file or in Netlify's build settings

3. Check the Build Logs The actual error message in Netlify's build logs will tell you exactly what's failing. Look for:

  • Missing dependencies (npm install or yarn install failures)
  • GraphQL query errors (often from Sanity schema changes)
  • API token/authentication issues
  • Memory or timeout errors

4. Repository URL Mismatch Since you changed your GitHub repo URL, make sure Netlify is pointing to the correct repository:

  • Go to Site settings → Build & deploy → Build settings
  • Under "Repository," click "Link to a different repository" if needed
  • The dash in your repo name shouldn't cause issues - GitHub and Netlify handle URL encoding automatically

5. CORS Configuration If you're getting API errors, you may need to add your Netlify URL to your Sanity project's CORS origins:

  • Go to manage.sanity.io
  • Select your project
  • Go to Settings → API → CORS Origins
  • Add your Netlify URL (both the temporary .netlify.app URL and any custom domain)

The specific error message in your Netlify build logs will point you to the exact issue. If you share that error here, the community can give you more targeted help!

What error messages do you get?
In what way does it fail?
I get this error that it fails during build. Even when I click on the link it shows me the old site, without any of additional work I have pushed to the repo, so I assumed it might be related to the url mismatch
Could you please show the complete errors directly from the deploy log?
Sure, one second
There should be more error output above. It likely is related to your
gatsby-config.js
or to a dependency conflict.
Do you have the
DEV_SSR
flag enabled in Gatsby?
If it wasn’t enabled by default, then I dont haven’t enabled. I’m not sure how to do that but I can google how to enable it.
It seems you are directly referencing images from the public folder.
Did you include the public folder or did you .gitignore it?
Does this project build successfully locally via
gatsby build && gatsby serve
?
You can enable
DEV_SSR
in your
gatsby-config.js
like this:
module.exports = {
  flags: {
    DEV_SSR: true
  },
  plugins: [...]
}
This will throw errors during development that you would normally only catch after building the project.
Possibly you will run into errors as soon as you activate this. That would be a good thing.
But it might also be the way you have imported those images. I would certainly advise to avoid the
public
folder whenever possible and use something like
src/assets/images
instead.
I just realised public is included in gitignore, should I remove it from there?
I tried building the project locally which brings to my second question, why did all the files changed and how can I go back? I remember previously with other projects when I run npm build, it creates a folder but without changing the files. You may see it in the screenshot here that all icons and files have changed after the local build.
Thank you, I will move them right now to assets folder and enable DEV_SSR
I would go the classic way of using images whenever possible. Otherwise you are going to miss out on a lot of the optimizations Gatsby provides.
See answer above.
this is the screenshot I was referring to above after the local build
Thank you very much! I’m gonna do exactly as per your answer above
In general, every website needs assets: images, stylesheets, scripts, etc. When using Gatsby, we recommend Importing Assets Directly in JavaScript files, because of the benefits it provides:

    Scripts and stylesheets are minified and bundled together to avoid extra network requests.
    Missing files cause compilation errors instead of 404 errors for your users.
    Result filenames include content hashes so you don't need to worry about browsers caching their old versions.

However, there is an escape hatch that you can use to add an asset outside of the module system.
-> this is an escape hatch and should be avoided whenever possible. A classic import and the files in the
src
folder should be the way to go.
Happy debugging! ☀️
Thank you so much!
I managed to fix the previous errors and now I have a new deployment error complaining about an invalid file name. I have googled the issue wasn’t able to find something helpful. Any clue how to fix this error?
For reference: solved here .
An easy solution could be achieved directly through Netlify UI.Navigate to your deployment settings > Build Settings > Publish Directory: (In here make sure it’s pointing to the public folder - /web/public) if it was only web, then it will try to deploy the node modules inside the web folder - This solution worked when using Sanity and Gatsby.

For Next.JS adding “out” in the publish directory input field on Netlify UI directly will also solve the problem.
👨‍💻

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?