Hugo Deploy Error


I want to migrate my site from Netliyf to Cloudflare Pages. After connecting my github repo and deploying I get the following error message:

Building sites … ERROR 2022/05/16 12:37:14 render of “page” failed: “/opt/buildhome/repo/layouts/_default/baseof.html:17:7”: execute of template failed: template: _default/elements.html:17:7: executing “_default/elements.html” at : can’t evaluate field IsProduction in type interface {}

I tried setting the IsProduction environment variable in the config.toml as well as the build command but no joy.

Where does the IsProduction variable need to be set in order to deploy on Pages?

Thanks, I set HUGO_ENVIRONMENT production under Settings->Environment variables but still get the same error.

Did I misunderstand the documentation?

Can you paste here your netlify toml hiding sensitive data?

isProduction isn’t an environment variable, it’s a Hugo variable.

You MUST set the environment variable HUGO_VERSION to the version of Hugo that you’re using. If you don’t set that, Pages uses a version of Hugo that your grandparents used when they were kids. I don’t know when isProduction was added to Hugo, but the default Hugo version in Pages is so old that my guess is that this is the problem.

in that case, where do I add that to Hugo? I tried adding it to config.toml but that didnt work. Any idea where it needs to be added?

Does Pages read the netlify.toml file?

In any case this is what I have (and tried this in both netlify.toml and config.toml):
publish = “public”
command = “hugo --minify --gc”

HUGO_VERSION = “0.87.0”

for = “/*” # This defines which paths this specific [[headers]] block will cover.

X-Frame-Options = “DENY”
X-XSS-Protection = “1; mode=block”
Referrer-Policy = “same-origin”
Strict-Transport-Security = “max-age=31536000; includeSubDomains; preload”

In the Cloudflare dashboard, in your Pages project, click Settings and then Environment Variables. You can (and must) add HUGO_VERSION there.

Screenshot of Environment Variables for Hugo Cloudflare Pages project that is in production