When I tried to deploy a Hugo website from GitHub to Netlify, I encountered many different errors. Then I figured out that the default Hugo version on Netlify is different from my local Hugo version. A simple solution to this problem is set the Hugo version on Netlify the same as the local version. Type the following command in the command line to check the local Hugo version first:
hugo version
Add a file “netlify.toml” to the repository hosting the Hugo code with the following content:
[context.production.environment]
HUGO_VERSION = "0.55.6"
An example toml file from Hugo website
[build]
publish = "public"
command = "hugo --gc --minify"
[context.production.environment]
HUGO_VERSION = "0.55.6"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "true"
[context.split1]
command = "hugo --gc --minify --enableGitInfo"
[context.split1.environment]
HUGO_VERSION = "0.55.6"
HUGO_ENV = "production"
[context.deploy-preview]
command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"
[context.deploy-preview.environment]
HUGO_VERSION = "0.55.6"
[context.branch-deploy]
command = "hugo --gc --minify -b $DEPLOY_PRIME_URL"
[context.branch-deploy.environment]
HUGO_VERSION = "0.55.6"
[context.next.environment]
HUGO_ENABLEGITINFO = "true"