I am working on a project that includes three modules, which we can call ‘site’, ‘theme’ and ‘utility’.
‘site’ is the top level, and defines a website. It loads ‘theme’, which contains the layouts, CSS etc. ‘theme’ needs to use a partial that is defined in ‘utility’. All three were duly initialized with go mod init, and I have been careful not to use the old-style way of referencing themes (i.e. putting a theme declaration in my config.toml file).
‘utility’ provides a partial called easy-utility (names have been changed to protect the innocent), which is invoked in layouts/partials/header.html in ‘theme’ with:
{{ partial "easy-utility" . }}
The config/_default/config.toml file in ‘theme’ contains:
[module]
[[module.imports]]
path = 'github.com/angusmci/utility'
The latest version of ‘utility’ is available at that location on Github.
If I try to run hugo mod get (or any other hugo command), however, I get an error:
ERROR failed to load modules: module "github.com/angusmci/utility" not found in "/Users/angus/site/themes/github.com/angusmci/utility"; either add it as a Hugo Module or store it in "/Users/angus/site/themes".: module does not exist
There is a fix for this, which is to add:
[[module.imports]]
path = 'github.com/angusmci/utility'
to the config.toml file in ‘site’, rather than ‘theme’. If I do that, then everything works.
This seems counterintuitive, however. I would like ‘site’ to be able to use ‘theme’ without needing to know (and list) all the supporting modules that ‘theme’ pulls in.
I assume that there must be something wrong with my approach. Is there a way to let modules import and use sub-modules without needing to explicitly import all the sub-modules in the highest-level module?