Hugo

Hugo Build Error with --gc --minify

Hi there,

I did something dumb and broke my Hermit Themed Hugo Site.

In brief, I upgraded Hugo to 0.58.0 and Hermit to the latest by removing and re-adding the submodule.

When I run hugo --gc --minify, I get the following error:

5:44:05 PM: Error: failed to prune cache "assets": remove /opt/build/repo/resources/_gen/assets/js/js/bundle.js_d11fe7b62c27961c87ecd0f2490357b9.content: no such file or directory

Where can I begin toward trying to figure this one out?

Thanks.

I’m obviously not getting something here…

What I’ve discovered is that if I manually copy the files below into the resources/_gen/js/js directory, I can run hugo --gc --minify exactly once, and then they disappear.

bundle.js_d11fe7b62c27961c87ecd0f2490357b9.content
bundle.js_d11fe7b62c27961c87ecd0f2490357b9.json

I can get this to build if I use: hugo --minify, omitting the --gc

Not sure if this is best practice. Anyone got milk?

Not sure what happens here, but you can try manually deleting the resources/_gen folder.

1 Like

Thanks for the help, @bep.

Apparently, its the existence of the files in resources/_gen/assets/js/js that make or break the use of the hugo command when the --gc flag is used.

Removing the --gc flag seems to do the trick, but I don’t know if that’s best practice.

Did you try my suggestion?

Hi @bep,

Yes, I did remove that folder and exclude it from the repo as well.

I believe the error is caused by --gc, as it’s trying to clean/prune something that is not there.

I see two js directories in the error message:

/opt/build/repo/resources/_gen/assets/js/js/bundle.js_d11fe7b62c27961c87ecd0f2490357b9.content

That doesn’t look right.

Thanks for the follow up, @pkollitsch.

Yes, that is kinda weird, but that’s how it is. I don’t think that’s the issue.

The issue was resolved by not using --gc with the hugo command.

When deploying to Netlify, I adjusted the netlify.toml accordingly.

:wink: --gc cleans out the resources folder. If it looks for a folder that does not exist then the error comes up. In my opinion you stumbled on a bug (cc @bep) where --gc builds the list of files to delete in the resources folder wrong. The double js has to come from somewhere and I am sure that if you run hugo with --gc, then take the paths from the errors and remove one js you will find the files in your file system. that’s the bug.

Hmm… I assume that the bug is somehow related to Hermit, as I’ve not done anything special, except install the theme and build from there.

Do you think that’s the case, and should I let the Hermit know, or should I look elsewhere for said bug?

The double js is correct.

This may be a bug, but the “–gc” routine does no file locking (which is by design), so if “someone or something” deletes these files while it’s running you may have a race …

That said, if it’s a bug it’s most likely a OS dependent path issue, but I would expect other people to also shout.

Hi! I have a similar problem:

I also use the Hermit theme, but just as a start to my own theme. After updating from Hugo 0.56 to 0.57.2, if I use --gc, I’ve got this error:

Error: failed to prune cache "assets": remove /opt/build/repo/resources/_gen/assets/js/js/main.js_d11fe7b62c27961c87ecd0f2490357b9.content: no such file or directory

This happens even if I change the name of main.js to any other name (Hermit has an assets/js/main.js file). And the problem occurs both at my machine (Manjaro Linux) and at Netlify.

If I update Hermit theme, the error changes to exactly the same as of @kimfucious (with bundle.js instead of main.js in error message). If I remove theme’s resources folder, then --gc works as expected. But Netlify uses theme directly from its repository (because it’s a submodule), thus resources folder is always there.

This relates to gohugoio/hugo#5745

1 Like