Problem with Hugo modules

My dislike [of Hugo modules] is limited to a single very specific Hugo module issue. I’ve wasted way too much time hunting for js issues only to discover that I need to run hugo mod clean.

This random download and deceptive error caused a lot of frustration and wasted time. Is there a way to figure out why Hugo downloads modules at random, and why the error message indicates a JS error instead of prescribing hugo mod clean?

Which operating system?
Have you set any Hugo environment variables?

What modules are you using?

Seeing the public repos for the modules (or at least the configuration of the modules, as well as the config of the module consumer) would make it much easier to look at what is going on.

It ‘shouldn’t’ matter if you do module clean (except during development, when modules are changing) in normal circumstances.

Also the JS error; is this in the browser? That would indicate to me that wrong version of module has been used of some component has been imported.

1 Like

Hi @jmooring

I am using macOS Monterey, Hugo is installed via homebrew

Hugo version: v0.95.0+extended darwin/amd64 BuildDate=unknown
golang version: go1.17.6 darwin/amd64

# go.mod
module site

go 1.17

require ( v1.7.1 // indirect v3.6.12+incompatible // indirect v4.1.4-0.20220225172002-466921877ec1+incompatible // indirect v0.0.0-20220128171254-2a316150d12b // indirect v1.0.6 // indirect v5.1.2-0.20220221192345-a84fec1dcf60+incompatible // indirect

after Hugo module download at random the error shown is js.Build failed

1st time took me many hours trying to find why failed then I realise it might happen due to auto module download by Hugo. using hugo mod clean fix the js.Build failed error. It happens at random when running Hugo or Hugo server.


hi @cshoredaniel

the js error is shown in the terminal or vscode when trying to use hugo or hugo server

thanks for taking the time

This helped me with some intermittent problems…

On Linux the default cache directory is /tmp/hugo_cache. This is a volatile location, cleared on reboot. I think the same is true on the Mac.

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:

This may not address the problem that you are experiencing, but it’s good starting point.


Thank you for your prompt response, @jmooring.

I believe this will solve the problem, unlike node modules, which downloads and stores all files in the Hugo project, Hugo modules only utilize those files temporarily (correct me if I’m wrong) and do not keep them in the project permanently.

Mac’s security and performance program clears temporary files in order to optimize the Mac’s performance. Because the modules are no longer available, this causes them to re download. I think I have it now :slight_smile:

This would benefit new Hugo module users if Hugo could identify the module download and advise running Hugo mod clean after an unsuccessful build.


1 Like

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