Go to your Netlify project deploy settings and find the Environment variables (direct link here). Add NODE_VERSION there with the value 18. You can also specify an exact Node version, such as v18.1.0, but by using just 18 Netlify will automatically choose the recommended v18 version.
Thats it! You will need to do a full cache clear most likely.
If you have your Gatsby v5 builds failing with Conflicting peer dependency
, overriding peer dependency
, or Could not resolve dependency
, you should add the property --legacy-peer-deps to your Netlify environment variables. You can add it by setting NPM_FLAGS environment variable to --legacy-peer-deps.