{"id":"ecb66ad28f2e6752","repo":"gohugoio/hugo","slug":"failed-to-init-mount-d-w","errorCode":null,"errorMessage":"failed to init mount %d: %w","messagePattern":"failed to init mount (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/config.go","lineNumber":233,"sourceCode":"\t\t\t\tc.replacementsMap[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])\n\t\t\t}\n\t\t}\n\n\t\tif c.replacementsMap != nil && c.Imports != nil {\n\t\t\tfor i, imp := range c.Imports {\n\t\t\t\tif newImp, found := c.replacementsMap[imp.Path]; found {\n\t\t\t\t\timp.Path = newImp\n\t\t\t\t\timp.pathProjectReplaced = true\n\t\t\t\t\tc.Imports[i] = imp\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor i, mnt := range c.Mounts {\n\t\t\tmnt.Source = filepath.Clean(mnt.Source)\n\t\t\tmnt.Target = filepath.Clean(mnt.Target)\n\t\t\tif err := mnt.init(logger); err != nil {\n\t\t\t\treturn c, fmt.Errorf(\"failed to init mount %d: %w\", i, err)\n\t\t\t}\n\t\t\tc.Mounts[i] = mnt\n\t\t}\n\n\t\tif c.Workspace == \"\" {\n\t\t\tc.Workspace = WorkspaceDisabled\n\t\t}\n\t\tif c.Workspace != WorkspaceDisabled {\n\t\t\tc.Workspace = filepath.Clean(c.Workspace)\n\t\t\tif !filepath.IsAbs(c.Workspace) {\n\t\t\t\tworkingDir := cfg.GetString(\"workingDir\")\n\t\t\t\tc.Workspace = filepath.Join(workingDir, c.Workspace)\n\t\t\t}\n\t\t\tif _, err := os.Stat(c.Workspace); err != nil {\n\t\t\t\t//lint:ignore ST1005 end user message.\n\t\t\t\treturn c, fmt.Errorf(\"module workspace %q does not exist. Check your module.workspace setting (or HUGO_MODULE_WORKSPACE env var).\", c.Workspace)\n\t\t\t}\n\t\t}","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/config.go#L215-L251","documentation":"Hugo (modules/config.go:233) returns this while decoding the explicit [module.mounts] section of the site config. Each declared mount's Source and Target are cleaned and then validated via Mount.init(); if a mount is invalid the error is wrapped with its zero-based index (%d) in the mounts list.","triggerScenarios":"decodeConfig() iterates c.Mounts from the user's module.mounts config and calls mnt.init(logger). A mount with a bad source (e.g. absolute path, path traversal, empty/invalid value) or an invalid target component causes init to fail for that index.","commonSituations":"Hand-written [[module.mounts]] blocks with an absolute source path, a target that isn't a known component root (content, static, layouts, assets, data, i18n, archetypes), or a lang attribute problem; copy-pasted mounts from other projects with wrong paths.","solutions":["Count into your [[module.mounts]] list using the index in the message (0-based) to find the bad entry.","Fix its source to a relative in-project path and its target to start with a valid component root like content/, static/, assets/.","Read the wrapped error text for the concrete validation failure.","Run hugo config to confirm the decoded mounts look as intended."],"exampleFix":"# before\n[[module.mounts]]\nsource = \"/abs/path/content\"\ntarget = \"content\"\n# after\n[[module.mounts]]\nsource = \"content\"\ntarget = \"content\"","handlingStrategy":"validation","validationCode":"// Pre-check top-level mounts in the project config\nfor i, m := range cfg.Module.Mounts {\n    if m.Source == \"\" {\n        return fmt.Errorf(\"module.mounts[%d]: missing source\", i)\n    }\n    if filepath.IsAbs(m.Source) {\n        return fmt.Errorf(\"module.mounts[%d]: source must be relative, got %q\", i, m.Source)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := modules.ApplyProjectConfigDefaults(mod, cfgs...); err != nil {\n    if strings.Contains(err.Error(), \"failed to init mount\") {\n        return fmt.Errorf(\"invalid [module.mounts] entry: %w\", err)\n    }\n    return err\n}","preventionTips":["Declare mounts explicitly instead of relying on implicit defaults when directories are non-standard","Keep mount sources relative to the module root, never absolute paths","Lint config files (hugo.toml/module section) in CI with `hugo config` before deploying"],"tags":["hugo","modules","mounts","config"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}