gohugoio/hugo · error

failed to apply mounts for project

Error message

failed to apply mounts for project: %w

What it means

In addAndRecurse, the project module itself (owner.projectMod true) has its mounts applied first; if applyMounts errors, the failure is wrapped with this project-specific context. It pinpoints the problem to the project's own mount configuration rather than a dependency's.

Solutions

  1. Inspect the project's [[module.mounts]] entries and verify each `source` exists relative to the project root.
  2. Create any missing mount source directories, or correct the source path.
  3. If you reorganised folders, update every mount source/target to match the new layout.
  4. Run `hugo config` to dump the resolved mounts and spot the bad entry.

Example fix

// before (hugo.toml): source renamed
[[module.mounts]]
source = "content"
target = "content"
[[module.mounts]]
source = "old-assets"
target = "assets"
// after: fix the stale source
[[module.mounts]]
source = "assets"
target = "assets"
Defensive patterns

Strategy: validation

Validate before calling

// Validate every project mount source exists before build
func validateProjectMounts(projectDir string, mounts []Mount) error {
  for _, m := range mounts {
    src := m.Source
    if !filepath.IsAbs(src) { src = filepath.Join(projectDir, src) }
    if _, err := os.Stat(src); err != nil {
      return fmt.Errorf("mount source missing: %s", src)
    }
  }
  return nil
}

Type guard

null

Try / catch

// On 'failed to apply mounts for project:', read the wrapped error to find the offending mount.

Prevention

When it happens

Trigger: The top-level hugo.toml/hugo.yaml defines a [[mounts]] block (or the project's module config has mounts) that fails normalisation — bad source path, missing source dir that isn't auto-created, or a mount whose source can't be resolved relative to the project.

Common situations: A [[module.mounts]] source pointing at a folder that doesn't exist (and isn't the publish dir or hugo_stats.json which Hugo auto-creates), an absolute source path with permission issues, or a recently-reorganised project where mount sources were not updated.

Related errors


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

Appendix: source

Thrown at modules/collect.go:370

	if !moduleImport.IgnoreConfig {
		if err := c.applyThemeConfig(ma); err != nil {
			return nil, err
		}
	}

	if err := c.applyMounts(moduleImport, ma); err != nil {
		return nil, err
	}

	return ma, nil
}

func (c *collector) addAndRecurse(owner *moduleAdapter) error {
	moduleConfig := owner.Config()
	if owner.projectMod {
		if err := c.applyMounts(Import{}, owner); err != nil {
			return fmt.Errorf("failed to apply mounts for project: %w", err)
		}
	}
	seen := make(map[pathVersionKey]bool)
	for _, moduleImport := range moduleConfig.Imports {
		if moduleImport.Disable {
			continue
		}

		// Prevent cyclic references.
		if v := c.isPathSeen(moduleImport.Path, owner); v != nil && v != owner {
			continue
		}

		tc, err := c.getAndCreateModule(owner, moduleImport)
		if err != nil {
			return err
		}

View on GitHub (pinned to 52c9bd7908)