gohugoio/hugo · error

must not be run from the file system root

Error message

must not be run from the file system root

What it means

`hugo mod ... ./...` performs a recursive module walk from the current directory. As a safety guard, if the working directory path is very short (len(dirname) < 5, i.e. the filesystem root), it refuses to run to prevent a recursive walk from / (mod.go:269-273).

Solutions

  1. cd into a project or workspace directory before running `hugo mod ... ./...`
  2. Ensure your shell/CI cwd is a real project path, not /
  3. Replace `./...` with an explicit module path if you must run from an unusual location

Example fix

# before (cwd is /)
hugo mod npm ./...
# after
cd ~/code/mywork && hugo mod npm ./...
Defensive patterns

Strategy: validation

Validate before calling

if dir, _ := os.Getwd(); len(dir) < 5 {
    return errors.New("refusing recursive walk from filesystem root")
}

Prevention

When it happens

Trigger: Running `hugo mod ... ./...` while the working directory is '/' or another path shorter than 5 characters.

Common situations: A CI container or shell whose cwd is /; running with cwd accidentally set to root; a script that cd'd to / before invoking hugo mod.

Related errors


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

Appendix: source

Thrown at commands/mod.go:272

					}

					var lastArg string
					if len(args) != 0 {
						lastArg = args[len(args)-1]
					}

					if lastArg == "./..." {
						args = args[:len(args)-1]
						// Do a recursive update.
						dirname, err := os.Getwd()
						if err != nil {
							return err
						}

						// Sanity chesimplecobra. We do recursive walking and want to avoid
						// accidents.
						if len(dirname) < 5 {
							return errors.New("must not be run from the file system root")
						}

						filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {
							if info.IsDir() {
								return nil
							}
							if info.Name() == "go.mod" {
								// Found a module.
								dir := filepath.Dir(path)

								cfg := config.New()
								cfg.Set("workingDir", dir)
								conf, err := r.ConfigFromProvider(configKey{counter: r.configVersionID.Add(1)}, flagsToCfg(cd, cfg))
								if err != nil {
									return err
								}
								r.Println("Update module in", conf.configs.Base.WorkingDir)
								client := conf.configs.ModulesClient

View on GitHub (pinned to 52c9bd7908)