Is there a limit to the number of image file that can be placed in the assets directory?
I experienced the eror below and traced it to a change I was trialling where I’d moved all images to the asset directory, believing that to be the correct place to put images that are used in multiple places within the site:
➜ colchesterphotosoc git:(main) hugo server
Watching for changes in /Users/matt/Code/colchesterphotosoc/{archetypes,assets,content,layouts,static}
Watching for config changes in /Users/matt/Code/colchesterphotosoc/config.toml
Start building sites …
hugo v0.147.5+extended+withdeploy darwin/arm64 BuildDate=2025-05-22T11:37:19Z VendorInfo=brew
Built in 1 ms
Error: error building site: failed to acquire a build lock: open /Users/matt/Code/colchesterphotosoc/.hugo_build.lock: too many open files
Apparently that can be fixed using ulimit -n unlimited on MacOS but I couldn’t get that to work.
During the test I was performing I had moved 10243 JPG files in the assets directory. My intention was then to start developing the pages to expose those on the site. Once I bumped into the issue above I parked that idea.
I’ve been playing around with this because I don’t like the way I’ve built my current site and want to find a structure that uses Hugo as it was intended.
(I’m just trying the same experiment again just to check that the same issue occurs with the latest build)
Without getting into the technical details, that seems like a large number of “global” resources. Or to put it another way, are any of those images specific to a given page, either a regular page or a section page?
Yeah, it’s a lot but it’s also a website for a camera club and I’ve got archives of member images going back years that people would like to see. Each image is included in a competition but also in a members gallery of just their images. That was sparked my reply to your excellent post. My images are used in multiple places, not just one. I think ideally they should go in the assets directory.
I already have almost 7000 images in the content directory and I just put another 10k images in assets and goodness me it now works fine. Perhaps the ulimit -n unlimited did work but I suspect it’s actually down to Hugo handling it now.
{{ range resources.ByType "image" }}
{{ with .Resize "200x" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
I had no problems with this on Ubuntu, either running hugo or hugo server. Perhaps someone with macOS experience/smarts has some insight into why you ran into the limit, but it sounds like it’s working for you now.
I tested the ulimit change when I was investigating this originally and I’m certain it didn’t work. As you point out though, it does now. This is good news. I’m currently working on a redesign so that’ll clean things up nicely.
Should point out that no single page in my site would ever display all the images. I’m certain Hugo could handle generating it but that’s not a use-case I will be needing for my site.