Some Netlify errors and how to solve them.
Netlify is a great platform to easily deploy your web apps within no time. Even so, there are chances you might encounter some errors while doing so. Here I discuss some of the errors which I faced while deploying my apps on Netlify and how I solved them.
Netlify — Page not found error
This one might often occur if you have deployed a ReactJS web app and also used React router dom. So your app would work fine in your localhost but when you try to visit the various routes on the Netlify deployed link, you might encounter a Page not found error.
This error occurs because the react-router-dom handles the routing activities on the client side. Netlify, being on the server side, does not know how to handle the routing activities, so it gives this page not found error when you visit any route (except the root one), on your deployed link.
How to fix : To solve this, you need to tell Netlify how to handle the route which is now not on the client side. For this Netlify offers a _redirects
file, using which you can specify where to redirect. So in your public
folder, create a file by the name _redirects
. In that file add the following:
/* /index.html 200
This redirects to the root of our app, which is nothing but the index.html file present in the public folder.
Netlify — Treating warnings as errors
This is another common error which recently started showing up after Netlify brought in some changes. So here what happens is if you have any warnings in your project Netlify will treat it as an error, which will be visible from the build logs as somethig like this:
How to fix: Login to Netlify. Click on your app name and go to Site settings. In the menu on the left, click on Build and Deploy. Now you will see Build settings here, click on Edit settings. In front of Build command
, add the following:
CI= npm run build
Click save, and you’re done!
Netlify — Not serving API fetch requests on http
In case you’re fetching or making a GET request from an api served on http
then Netlify will not let that happen and cause your site to crash. This is because Netlify does not serve http
but only https
queries.
How to fix: In my opinion, the best method to fix this error would be to use only https
instead of http
to serve your content. Other than fixing this error, it would also ensure more safety for your app. So here’s what you can do:
- Often, the
https
for the service already exists, so you can try to just add an ‘s’ following thehttp
and check if that solves your issue. - In case the
https
version does not exist for that service, then it would be best to contact the owner and request them to make anhttps
version of their service available.
Hope you found this blog helpful, if you encounter any more similar errors while building your project on Netlify do feel free to share them with me!