{"id":"637043ed99d816a0","repo":"gohugoio/hugo","slug":"errnotexist","errorCode":"ErrNotExist","errorMessage":"module does not exist","messagePattern":"module does not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/collect.go","lineNumber":49,"sourceCode":"\t\"github.com/gobwas/glob\"\n\t\"github.com/gohugoio/hugo/common/herrors\"\n\t\"github.com/gohugoio/hugo/common/hmaps\"\n\t\"github.com/gohugoio/hugo/common/loggers\"\n\t\"github.com/gohugoio/hugo/common/paths\"\n\t\"github.com/gohugoio/hugo/common/version\"\n\t\"golang.org/x/mod/module\"\n\n\t\"github.com/spf13/cast\"\n\n\t\"github.com/gohugoio/hugo/parser/metadecoders\"\n\n\t\"github.com/gohugoio/hugo/hugofs/files\"\n\n\t\"github.com/gohugoio/hugo/config\"\n\t\"github.com/spf13/afero\"\n)\n\nvar ErrNotExist = errors.New(\"module does not exist\")\n\nconst vendorModulesFilename = \"modules.txt\"\n\nfunc (h *Client) Collect() (ModulesConfig, error) {\n\tmc, coll := h.collect(true)\n\tif coll.err != nil {\n\t\treturn mc, coll.err\n\t}\n\n\tif err := (&mc).setActiveMods(h.logger); err != nil {\n\t\treturn mc, err\n\t}\n\n\tif h.ccfg.HookBeforeFinalize != nil {\n\t\tif err := h.ccfg.HookBeforeFinalize(&mc); err != nil {\n\t\t\treturn mc, err\n\t\t}\n\t}","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/collect.go#L31-L67","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before: imports declared but no go.mod\nhugo build  # -> module does not exist\n# after\nhugo mod init github.com/me/mysite\nhugo mod get\nhugo build","handlingStrategy":"type-guard","validationCode":"if _, err := os.Stat(filepath.Join(dir, \"go.mod\")); err != nil {\n    // module dir not present — run `hugo mod get` first\n}","typeGuard":"func isModuleNotExist(err error) bool {\n    return errors.Is(err, modules.ErrNotExist)\n}","tryCatchPattern":"if err := collect(); err != nil {\n    if errors.Is(err, modules.ErrNotExist) {\n        // prompt: run `hugo mod get ./...` to populate the module cache\n    }\n    return err\n}","preventionTips":["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"],"tags":["hugo-modules","sentinel-error","configuration","themes"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}