Runtime error: invalid memory address or nil pointer dereference


I am using RStudio on Mac. I’ve installed Hugo, Blogdown, and the Hugo-academic theme as well.
I see the following error with the new RStudio (v1.2.616).

Building sites … ERROR 2018/05/08 11:58:13 Failed to render “theme/publication/single.html”: runtime error: invalid memory address or nil pointer dereference
Serving the directory /Users/janani/Google_Drive/Personal/AJ/jananiravi at
To stop the server, run servr::daemon_stop(“140699771731016”) or restart your R session

And I see the ftp-like rendering of the webpage:


Did you update the themesDir variable on your config page?


I have the line theme = "hugo-academic" in config.toml
and an updated academic theme folder under my home folder in /themes/hugo-academic/

Are you referring to anything else that I may be missing? thanks.


It’s difficult to debug this without site source. Can you share a minimal version of your site that reproduces this problem?


Not quite sure if any of that is the problem, based on that error message.


Here’s the .Rproj folder: I am waiting for a minimal working version before I post it on GitHub. thanks!


Possibly, yes. I was responding to the themes question raised by @KalikaKay just in case the theme installation wasn’t done properly.


OK, but just curious why having a working version would gate that… you can also delete a temp repo or force push “working commits” later. I would choose to not force push commits especially in such cases… the commits that making non-working stuff working are very self-educational :slight_smile:


You are missing one or more files in there (missing the gallery shortcode, missing the css/parse_theme.css) … running hugo gives me:

Building sites … ERROR 2018/05/08 14:31:50 Unable to locate template for shortcode "gallery" in page "post/"
ERROR 2018/05/08 14:31:50 Error while rendering "home" in "": template: theme/index.css:4:4: executing "theme/index.css" at <partial "css/parse_t...>: error calling partial: Partial "css/parse_theme.css" not found

Did you happen to stitch together site content specific to one theme with an arbitrary different theme?

Update: Turns out you uploaded incomplete theme on Google Drive… fresh clone of fixed those errors.

And now I get:

Building sites … ERROR 2018/05/08 14:39:32 Failed to render "theme/publication/single.html": runtime error: invalid memory address or nil pointer dereference

I’ll update if I figure this out.


It’s a bug in the theme…

diff --git a/layouts/partials/publication_links.html b/layouts/partials/publication_links.html
index 1b21ef1..802e9db 100644
--- a/layouts/partials/publication_links.html
+++ b/layouts/partials/publication_links.html
@@ -31,10 +31,12 @@
 {{ end }}
 {{ if $.Params.projects }}
     {{ range $.Params.projects }}
-<a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ ($.Site.GetPage "page" "project" .).Permalink }}">
+        {{ with ($.Site.GetPage "page" "project" .) }}
+            <a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ .Permalink }}">
                 {{ i18n "btn_project" }}
         {{ end }}
+    {{ end }}
 {{ else }}
     {{ with $.Params.url_project }}
         <a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ . | absLangURL }}" target="_blank" rel="noopener">

The above change fixes it.

The problem was that it was trying to get a page “foo” under the “project/” section where you would have project = "foo" in your front-matter. But even if that page did not exist under project/ section, it would try to get .Permalink out of that… effectively doing nil.Permalink. Now that .Permalink step happens only if the .GetPage succeeds.


Thanks! That temporarily fixes the publication/single.html error.

I’ve progressed to the following error now:

ERROR 2018/05/08 15:11:12 Failed to render “theme/talk/single.html”: runtime error: invalid memory address or nil pointer dereference

I’m guessing something similar has to be edited here.


Most likely… I’ll leave that debug to you now :slight_smile:

In general, it’s always better to do:

{{ with ($.Site.GetPage "KIND" "SECTION" .) }}
    {{ .Permalink }}
{{ end }}

instead of:

{{ ($.Site.GetPage "KIND" "SECTION" .).Permalink }}

… In the latter approach, you never know if you are applying .Permalink on nil or a page object.

I have opened an issue for one I fixed:


I suggest that you make the same fixes at all of these places:

37:    <a href="{{ ($.Site.GetPage "taxonomyTerm" "categories" .).Permalink }}">{{ . }}</a

6:  <a class="btn btn-primary btn-outline" href="{{ ($.Site.GetPage "taxonomyTerm" "tags" .).Permalink }}">{{ . }}</a>

25:<a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ ($.Site.GetPage "page" "project" .).Permalink }}">

35:            <a href="{{ ($.Site.GetPage "section" "publication").Permalink }}#{{ . | urlize }}">

13:      <a href="{{ ($.Site.GetPage "section" "post").Permalink }}">

12:      <a href="{{ ($.Site.GetPage "section" "talk").Permalink }}">

12:      <a href="{{ ($.Site.GetPage "section" "publication").Permalink }}">

27:          <a href="{{ ($.Site.GetPage "taxonomyTerm" "tags" $name).Permalink }}" style="font-size:{{ $fontSize }}rem">{{ $name }}</a>


Thank you, @kaushalmodi I am making those changes now. I’m new to HTML and would have never figured this out. Really appreciate your timely help. And I have moved the folder out of Google_Drive into my repo. I shall watch the hugo-academic thread from further updates from @gcushen


@bep Is it possible to catch such exceptions and improve the error message so that the user is pointed to the line in the template where that .Permalink call is happening on nil? If so, should I open an issue?


Hmm … I think I have investigated this before, but I may give it another shot. The stack trace (that we don’t show) is not useful, as it just points to some point in Go’s framework (and not the line in the template). But I have seen some talk about “template nils” suggesting that we could maybe possibly do better. We should at least talk to the Go people about it and see if there are something we can do. I got pretty good training tracking down these situations, but I can imagine the pain of people new to Hugo.

Create an issue, but I will not promise anything …


Done. Thanks!


I’ve got the same error. I’ve had a break from coding in almost a month, and when I got back, I got the nil pointer error when running hugo serve. I haven’t made any changes. For me it looks like something new introduced in version 0.40.3 or newer (My last commit was on May 8th).

I’ve just tested that 0.40.2 works.

0.40.3 burps out the error, but then it serves the site (with errors - missing footers on some pages).

0.41 and 0.42 doesn’t work.