Can't give argument to non-function getenv

<(getenv "HUGO_ENV") eq "production">: can't give argument to non-function getenv "HUGO_ENV"

I was digging around to find out, how this error might come up. Using the latest version at this time:

Hugo Static Site Generator v0.74.3-DA0437B4/extended linux/amd64 BuildDate: 2020-07-23T16:30:30Z

These lines:

   10: 		{{ if (getenv "HUGO_ENV") eq "production" }}
   11  			{{ template "_internal/google_analytics.html" . }}
   12  		{{ end }}

in _baseof.html lead to plenty of these errors and stop site compilation. I read this and some other posts about this kind of error, but I fail to “get it” in regards to my code line.

Can someone please enlighten me what the problem is here? It worked back in 0.53 (one of these older pages) and in other more current posts I see getenv used quite often, so it’s not a deprecated function.

1 Like
{{ if eq (getenv "HUGO_ENV") "production" }}

well, thankyou :slight_smile: this was a typical forest vs tree moment :smiley:

1 Like

I would recommend hugo.IsProduction for this – it does pick up HUGO_ENV or HUGO_ENVIRONMENT etc.

1 Like

I used that and it works well… Perfect.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.