🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

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?
Jun 22, 2021, 10:55 AM
What error messages do you get?
Jun 22, 2021, 10:56 AM
In what way does it fail?
Jun 22, 2021, 10:56 AM
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
Jun 22, 2021, 10:59 AM
Could you please show the complete errors directly from the deploy log?
Jun 22, 2021, 10:59 AM
Sure, one second
Jun 22, 2021, 11:00 AM
There should be more error output above. It likely is related to your
gatsby-config.js
or to a dependency conflict.
Jun 22, 2021, 11:06 AM
Do you have the
DEV_SSR
flag enabled in Gatsby?
Jun 22, 2021, 11:07 AM
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.
Jun 22, 2021, 11:09 AM
It seems you are directly referencing images from the public folder.
Jun 22, 2021, 11:12 AM
Did you include the public folder or did you .gitignore it?
Jun 22, 2021, 11:12 AM
Does this project build successfully locally via
gatsby build && gatsby serve
?
Jun 22, 2021, 11:12 AM
You can enable
DEV_SSR
in your
gatsby-config.js
like this:
Jun 22, 2021, 11:13 AM
module.exports = {
  flags: {
    DEV_SSR: true
  },
  plugins: [...]
}
Jun 22, 2021, 11:13 AM
This will throw errors during development that you would normally only catch after building the project.
Jun 22, 2021, 11:13 AM
Possibly you will run into errors as soon as you activate this. That would be a good thing.
Jun 22, 2021, 11:14 AM
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.
Jun 22, 2021, 11:14 AM
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.
Jun 22, 2021, 11:16 AM
Thank you, I will move them right now to assets folder and enable DEV_SSR
Jun 22, 2021, 11:17 AM
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.
Jun 22, 2021, 11:17 AM
See answer above.
Jun 22, 2021, 11:17 AM
this is the screenshot I was referring to above after the local build
Jun 22, 2021, 11:17 AM
Thank you very much! I’m gonna do exactly as per your answer above
Jun 22, 2021, 11:18 AM
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.
Jun 22, 2021, 11:18 AM
-> 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.
Jun 22, 2021, 11:19 AM
Happy debugging! ☀️
Jun 22, 2021, 11:19 AM
Thank you so much!
Jun 22, 2021, 11:20 AM
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?
Jun 22, 2021, 12:49 PM
For reference: solved here .
Jun 22, 2021, 7:10 PM
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.
👨‍💻
Jun 22, 2021, 7:18 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?