{"id":"af7ec310de375eb4","repo":"gohugoio/hugo","slug":"failed-to-init-mount-q-d-w","errorCode":null,"errorMessage":"failed to init mount %q %d: %w","messagePattern":"failed to init mount %q (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/config.go","lineNumber":162,"sourceCode":"\t\t\t\t\tMatrix: sitesmatrix.StringSlices{\n\t\t\t\t\t\tLanguages: []string{l.Lang},\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Static mounts are a little special.\n\t\t\tif component == files.ComponentFolderStatic {\n\t\t\t\tstaticDirs := cfg.StaticDirs()\n\t\t\t\tfor _, dir := range staticDirs {\n\t\t\t\t\tmounts = append(mounts, Mount{Sites: sites, Source: dir, Target: component})\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif dir != \"\" {\n\t\t\t\tmnt := Mount{Source: dir, Target: component, Sites: sites}\n\t\t\t\tif err := mnt.init(logger); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to init mount %q %d: %w\", lang, i, err)\n\t\t\t\t}\n\t\t\t\tmounts = append(mounts, mnt)\n\t\t\t}\n\t\t}\n\t}\n\n\tmoda.mounts = append(moda.mounts, mounts...)\n\n\tmoda.mounts = filterDuplicateMounts(moda.mounts)\n\n\treturn nil\n}\n\n// DecodeConfig creates a modules Config from a given Hugo configuration.\nfunc DecodeConfig(logger logg.Logger, cfg config.Provider) (Config, error) {\n\treturn decodeConfig(logger, cfg, nil)\n}\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/config.go#L144-L180","documentation":"Hugo (modules/config.go:162) returns this while building the default component mounts (content, layouts, static, etc.) for a module. When a directory config like contentDir is set per-language, Hugo creates one mount per language and calls Mount.init() to validate/normalize it; if that validation fails, the error is wrapped with the language code (%q) and component index (%d).","triggerScenarios":"Runs during config decoding when Hugo synthesizes mounts from legacy dir settings (contentDir, layoutDir, staticDir, i18nDir, archetypeDir, assetDir, dataDir), including per-language variants such as languages.en.contentDir. Mount.init() rejects invalid mount definitions, e.g. an absolute or traversal source path or an otherwise malformed source/target.","commonSituations":"Multilingual sites setting contentDir/staticDir per language to an absolute path or a path outside the project; migrating old configs where dir settings point at invalid locations; typos in per-language directory settings.","solutions":["Look at the wrapped inner error — it names the actual mount problem (usually the source path).","Make the offending dir setting (contentDir, staticDir, etc., possibly under languages.<lang>) a relative path inside the project, not absolute or containing ..","If per-language dirs are involved, verify each language's dir settings individually.","Prefer explicit [[module.mounts]] entries over legacy dir settings for complex layouts."],"exampleFix":"# before (hugo.toml)\n[languages.fr]\ncontentDir = \"/home/me/other/content-fr\"\n# after\n[languages.fr]\ncontentDir = \"content-fr\"","handlingStrategy":"validation","validationCode":"// Validate each module's mounts before loading config\nfor i, m := range modCfg.Mounts {\n    if strings.TrimSpace(m.Source) == \"\" || strings.TrimSpace(m.Target) == \"\" {\n        return fmt.Errorf(\"mount %d: source and target must be set\", i)\n    }\n    if !validTargetPrefix(m.Target) { // content, layouts, static, assets, data, i18n, archetypes\n        return fmt.Errorf(\"mount %d: target %q must start with a known component folder\", i, m.Target)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := client.Init(); err != nil {\n    var pe *modules.PathError\n    // fall back to string inspection since error is wrapped with %w\n    if strings.Contains(err.Error(), \"failed to init mount\") {\n        log.Fatalf(\"check [module.mounts] in config: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep mount targets limited to Hugo's component folders (content, layouts, static, assets, data, i18n, archetypes)","Use forward slashes in mount source/target paths even on Windows","Verify mount source directories exist relative to the module root before building","Run `hugo mod graph` / `hugo config` after editing [module.mounts] to catch bad entries early"],"tags":["hugo","modules","mounts","config","multilingual"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}