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:
- Recommended: Update your Hugo version to
0.120.0
or newer. At the time of writing this, version0.134.2
is the latest version. - In case that is not possible: Remove the
.IsServer
check from your template code. This typically doesnt impact your site much (as production builds will not be impacted at all andhugo serve
development builds will typically only be changed slightly), but you might need to test your site to ensure everything works as expected.
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.