How to fix "VipsJpeg: Premature end of JPEG file" for Gatsby + Contentful + Netlify

Gatsby Feb 24, 2020

My Gatsby website was running and building correctly in my local but when Netlify started the deployment, the build failed because the following error

VipsJpeg: Premature end of JPEG file

This is the full log of the error

So I did a research but there wasn't any specific fix for it and my code wasn't having any error but there was a main difference between Netlify and my local and it was the NodeJS version, in my local I am using v8.16.2 and Netlify was using v10.19.0 so I created an .nvmrc file in the root of my project and inside only the NodeJS version I am using which is v8.16.2 then I pushed it and it worked!