gohugoio/hugo · error
ErrNotExist
ErrNotExist
Error message
module does not exist
What it means
`ErrNotExist` (modules/collect.go:49) is the sentinel `errors.New("module does not exist")` used by the modules package to signal that a referenced module cannot be located anywhere — not in go.mod-resolved modules, the vendor dir, or the themes directory. It is wrapped (via `wrapModuleNotFound`) around more descriptive messages so callers can `errors.Is(err, modules.ErrNotExist)` and react, e.g. by suggesting `hugo mod init` or downloading.
Source
Thrown at modules/collect.go:49
"github.com/gobwas/glob"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/hmaps"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/common/version"
"golang.org/x/mod/module"
"github.com/spf13/cast"
"github.com/gohugoio/hugo/parser/metadecoders"
"github.com/gohugoio/hugo/hugofs/files"
"github.com/gohugoio/hugo/config"
"github.com/spf13/afero"
)
var ErrNotExist = errors.New("module does not exist")
const vendorModulesFilename = "modules.txt"
func (h *Client) Collect() (ModulesConfig, error) {
mc, coll := h.collect(true)
if coll.err != nil {
return mc, coll.err
}
if err := (&mc).setActiveMods(h.logger); err != nil {
return mc, err
}
if h.ccfg.HookBeforeFinalize != nil {
if err := h.ccfg.HookBeforeFinalize(&mc); err != nil {
return mc, err
}
}View on GitHub ↗ (pinned to 8a468df065)
Solutions
- If importing remote modules, initialize the project as a module: `hugo mod init github.com/you/site`, then `hugo mod get`.
- If using a classic theme, ensure the directory exists at themes/<name> (e.g. `git submodule update --init`).
- Check the import path spelling in your Hugo configuration.
- Run `hugo mod graph` to identify which import fails.
Example fix
# before: imports declared but no go.mod hugo build # -> module does not exist # after hugo mod init github.com/me/mysite hugo mod get hugo build
Defensive patterns
Strategy: type-guard
Validate before calling
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err != nil {
// module dir not present — run `hugo mod get` first
} Type guard
func isModuleNotExist(err error) bool {
return errors.Is(err, modules.ErrNotExist)
} Try / catch
if err := collect(); err != nil {
if errors.Is(err, modules.ErrNotExist) {
// prompt: run `hugo mod get ./...` to populate the module cache
}
return err
} Prevention
- Run `hugo mod get`/`hugo mod tidy` before building so all imports are materialized
- Use errors.Is with the exported ErrNotExist sentinel, not string matching
- Vendor modules (`hugo mod vendor`) for hermetic CI builds
When it happens
Trigger: Module collection (`Client.Collect`) fails to resolve an import: the path looks like a module but no go.mod project is initialized, the module isn't in the module cache, and there's no matching directory under themesDir. Also surfaced by `hugo mod` subcommands operating on a missing module.
Common situations: Adding `[[module.imports]]` for a remote theme without running `hugo mod init` first (no go.mod, so nothing can be fetched); referencing a theme name with no corresponding themes/<name> folder; cloned repo missing its themes submodule.
Related errors
- invalid module path %q; must be relative to themesDir when d
- go command failed: %s
- module %q not found
- %q not found
- failed to apply mounts for project: %w
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/637043ed99d816a0.json.
Report an issue: GitHub ↗.