gohugoio/hugo · error

not found

Error message

%q not found

What it means

Final existence gate in getAndCreateModule: a moduleDir was computed (via go module, replace, or themesDir resolution) but afero.Exists reports it absent on the filesystem. Distinct from 471 in that the directory path was resolved, just not present — typically a broken replace, a vanished cache, or a race where the dir was removed mid-build.

Solutions

  1. For cached Go modules: `go clean -modcache && hugo mod clean` then rebuild to re-download.
  2. For replaced modules, verify the replace target directory exists at the path go list reported.
  3. For vendored builds, regenerate: `hugo mod vendor`.
  4. Ensure nothing (antivirus, CI cleanup, parallel builds) deletes the module dir during the build.

Example fix

// before: replace target vanished
replace github.com/x/y => ../y
// after: ensure target exists or re-vendor
git clone https://github.com/x/y ../y
hugo mod vendor
Defensive patterns

Strategy: validation

Validate before calling

// Verify resolved module dirs actually exist before relying on them
import "os"

func ensureModuleDirExists(dir string) error {
  info, err := os.Stat(dir)
  if err != nil { return fmt.Errorf("module dir missing: %s", dir) }
  if !info.IsDir() { return fmt.Errorf("module path is not a dir: %s", dir) }
  return nil
}

Type guard

null

Try / catch

// if errors.Is(err, fs.ErrNotExist) { re-download or re-vendor }

Prevention

When it happens

Trigger: go list returned a Dir for a module but that directory no longer exists (cache evicted, replace target deleted, vendored dir partially removed), or themesDir path computed but the folder was deleted between resolution and this check.

Common situations: Manual deletion of part of the module cache, a replace directive pointing at a moved folder, vendored modules where vendor/<path> is incomplete, or a race with another process cleaning the build dir.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/e64c4f3929e7cab8. Report an issue: GitHub.

Appendix: source

Thrown at modules/collect.go:331

			// Fall back to project/themes/<mymodule>
			if moduleDir == "" {
				var err error
				moduleDir, err = c.createThemeDirname(modulePath, owner.projectMod || moduleImport.pathProjectReplaced)
				if err != nil {
					c.err = err
					return nil, nil
				}
				if found, _ := afero.Exists(c.fs, moduleDir); !found {
					//lint:ignore ST1005 end user message.
					c.err = c.wrapModuleNotFound(fmt.Errorf(`module %q not found in %q; either add it as a Hugo Module or store it in %q.`, modulePath, moduleDir, c.ccfg.ThemesDir))
					return nil, nil
				}
			}
		}
	}

	if found, _ := afero.Exists(c.fs, moduleDir); !found {
		c.err = c.wrapModuleNotFound(fmt.Errorf("%q not found", moduleDir))
		return nil, nil
	}

	if !strings.HasSuffix(moduleDir, fileSeparator) {
		moduleDir += fileSeparator
	}

	ma := &moduleAdapter{
		dir:          moduleDir,
		vendor:       vendored,
		gomod:        mod,
		version:      versionMod,
		versionQuery: requestedVersionQuery,
		// This may be the owner of the _vendor dir
		owner: realOwner,
	}

	if mod == nil {

View on GitHub (pinned to 52c9bd7908)