Go.sum and hugo mod cleanup

Hello!

In our project we are using modules to a large extent. At times, we have some of the users run into problems where Hugo is unable to detect shortcodes that are found in the modules and often times will need to delete the go.mod file and perform a hugo mod clean.

I was curious what causes this to buildup (sometimes our users need do this weekly and it’s a bit cumbersome), what is more the root problem. Is there anyway to have this done routinely in the background so that it becomes more efficient?

Thank you!

In my experience it’s the updates in the used modules. My releasing script does run the following:

hugo mod get -u ./...
hugo mod tidy

The first line updates all modules, the second one removes outdated entries from go.sum - then add go.mod and go.sum to your release commit.

After that you might want to check/test if all is working. then run a release and your users can stop worrying about cleaning up manually.

Another solution I am looking into currently is “vendoring” modules into my own modules/repos. Not sure this might help, but it will probably cut down the amount of available versions.

@Kimberley_Brown

On Linux the default cache directory is /tmp/hugo_cache. This is a volatile location, cleared on reboot.

Set the HUGO_CACHEDIR environment variable to something other than the system temporary directory, but make sure that it is outside of your project path. Related comments:

Without knowing all the details, I don’t know if this will resolve the problems your users are experiencing, but it’s a wise move nevertheless.

2 Likes

Hmm. sorry, but it’s not cleared on reboot (at least on my linuxes). On Ubuntu for instance you can set in the settings (I think in Privacy) when (after how many days) the temp directory content is cleared. It’s however by definition a volatile location, for sure. Shouldn’t vendoring help with this? (@Kimberley_Brown ignore this sidestepping, it might be a waste of time… trying to learn something here :slight_smile: )

With a clean install of Ubuntu 20.04.4 LTS…

$ du -bs /tmp/hugo_cache/
221178774	/tmp/hugo_cache/

reboot

$ du -bs /tmp/hugo_cache/
du: cannot access '/tmp/hugo_cache/': No such file or directory

Thank you for your reply!

I have a follow-up question on this (and please excuse if I’m misunderstanding, still quite new to this), but this release script runs when you’re pushing to a production platform?

Basically our setup is that the tech writers who are using this run hugo server to work on their projects locally which then prompts the download and collection of the associated modules needed for the project. The error happens at this stage when it starts building the site.

$ hugo server
hugo: downloading modules …
hugo: collected modules in 3429 ms
Start building sites …
hugo v0.90.1-48907889+extended windows/amd64 BuildDate=2021-12-10T10:56:41Z VendorInfo=gohugoio
Error: Error building site: "removed url for privacy reasons" failed to extract shortcode: template for shortcode "get_global_var" not found
Built in 133 ms

To resolve the build error, the go.sum needs to be deleted and then we have to run the hugo mod clean. What I’m wondering if locally we could have the hugo mod clean run at the time it’s collecting the modules or before it starts building. I’m still understanding how this works and what the purpose of the go.sum file is. We’re also running on windows if that makes a difference.

I appreciate you taking the time to reply!