I am converting a bunch of my websites to use Hugo Modules based theme and component fetching instead of using git submodules.
During this conversion, I believe I have come across a bug.
My config.toml of few sites use an output format defined in a separate git repo aka module.
So when I switched to using Hugo Modules, I simply removed the
themes/ directory and add module imports to my theme-turned-module.
Note that my site is already building using the old themes/ approach and I am just converting to Hugo Modules approach.
So I would need to create a new
hugo mod init something.something. The problem is that because my config.toml references output formats which will be fetched from the modules, Hugo doesn’t find the definition of those formats yet, and quits with this error without generating go.mod.
WARN 2022/01/20 14:31:36 module "github.com/kaushalmodi/hugo-atom-feed" not found; either add it as a Hugo Module or store it in "/home/kmodi/hugo/hugo_mwe/themes".: module does not exist Error: from config: failed to resolve output format "ATOM" from site config
One can easily reproduce this error by adding this to their site config, deleting their existing
go.sum and then running
hugo mod init something.something:
[module] [[module.imports]] path = "github.com/kaushalmodi/hugo-atom-feed" [outputs] home = ["HTML", "RSS", "ATOM"] # default = ["HTML", "RSS"]
Alternatively, you can clone my minimal reproducible example repo:
git clone https://gitlab.com/hugo-mwe/hugo-mwe cd hugo-mwe git checkout mod-init-fail hugo mod init something.something
You should see a similar error like above and no
go.mod will be created.
Workaround: Comment out the
output lines from config.toml, run the
hugo mod init .. command and then uncomment those
It took me some unreasonable amount to time to figure out what the problem was. I hope this is categorized as a bug and fixed.
Suggestion: Skip the checking of site config.toml correctness when user is running
hugo mod init ...