How to fix Hugo: can't evaluate field IsServer in type interface {}

Problem:

When building your Hugo site, you see an error message like the following:

03:27:57.943	ERROR render of "page" failed: "/opt/buildhome/repo/themes/tailbliss/layouts/_default/baseof.html:5:7": execute of template failed: template: _default/single.html:5:7: executing "_default/single.html" at <partial "head.html" .>: error calling partial: "/opt/buildhome/repo/themes/tailbliss/layouts/partials/head.html:25:6": execute of template failed: template: partials/head.html:25:6: executing "partials/head.html" at <hugo>: can't evaluate field IsServer in type interface {}

Solution

The issue is caused by Hugo not finding .IsServer:

can't evaluate field IsServer in type interface {}

for example in the following template code:

{{ if hugo.IsServer }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" />
{{ end }}

However, .IsServer was only added to Hugo in version 0.120.0, so if you’re using an older version, you’ll see this error..

The fix is easy. You can either:

Note: For Cloudflare Pages you can set the deployment environment variable HUGO_VERSION to 0.120.0 or newer to fix this issue. I tested this with 0.134.2 and it worked fine.