{"id":"536b67bd03d7397d","repo":"gohugoio/hugo","slug":"the-configured-defaultcontentrole-q-does-not-exis","errorCode":null,"errorMessage":"the configured defaultContentRole %q does not exist","messagePattern":"the configured defaultContentRole %q does not exist","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/roles/roles.go","lineNumber":183,"sourceCode":"\n\t// Sort by weight if set, then by name.\n\tsort.SliceStable(r.Sorted, func(i, j int) bool {\n\t\tri, rj := r.Sorted[i], r.Sorted[j]\n\t\tif ri.Weight == rj.Weight {\n\t\t\treturn ri.Name < rj.Name\n\t\t}\n\t\tif rj.Weight == 0 {\n\t\t\treturn true\n\t\t}\n\t\tif ri.Weight == 0 {\n\t\t\treturn false\n\t\t}\n\t\treturn ri.Weight < rj.Weight\n\t})\n\n\tif !defaultSeen {\n\t\tif defaultContentRoleProvided {\n\t\t\treturn \"\", fmt.Errorf(\"the configured defaultContentRole %q does not exist\", defaultContentRole)\n\t\t}\n\t\t// If no default role is set, we set the first one.\n\t\tfirst := r.Sorted[0]\n\t\tfirst.Default = true\n\t\tr.roleConfigs[first.Name] = first.RoleConfig\n\t\tr.Sorted[0] = first\n\t\tdefaultContentRole = first.Name\n\t}\n\n\treturn defaultContentRole, nil\n}\n\nfunc (r RolesInternal) Has(role string) bool {\n\t_, found := r.roleConfigs[role]\n\treturn found\n}\n\nfunc DecodeConfig(defaultContentRole string, m map[string]any) (*config.ConfigNamespace[map[string]RoleConfig, RolesInternal], string, error) {","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/roles/roles.go#L165-L201","documentation":"After collecting all configured roles, Hugo checks that the explicitly configured `defaultContentRole` matches one of them. If the user provided a `defaultContentRole` and no role with that name exists in the roles map, config load fails with this error. (When no default is provided, Hugo silently promotes the first sorted role instead.)","triggerScenarios":"Setting `defaultContentRole = \"x\"` in site config where `x` is not a key under `roles`; renaming or deleting a role without updating `defaultContentRole`; environment-specific config overriding `roles` but not `defaultContentRole`.","commonSituations":"Refactoring role names and missing one reference; per-environment config files (config/production) redefining the roles map so the default from the base config no longer exists; case mismatch between the default and the role key.","solutions":["Make `defaultContentRole` exactly match one of the keys under `roles` (case-sensitive).","Add the missing role definition under `roles` if it was removed accidentally.","Remove `defaultContentRole` entirely to let Hugo pick the first role automatically.","Check merged config with `hugo config` to see which roles survive environment merging."],"exampleFix":"# before\ndefaultContentRole = \"members\"\n[roles.member]\n\n# after\ndefaultContentRole = \"member\"\n[roles.member]","handlingStrategy":"validation","validationCode":"if _, ok := definedRoles[cfg.DefaultContentRole]; !ok {\n    return fmt.Errorf(\"defaultContentRole %q not in roles %v\", cfg.DefaultContentRole, keys(definedRoles))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always declare defaultContentRole as one of the roles defined in the same config","Cross-check role references in a config-validation CI step before deploying","When renaming a role, grep the config for all references (defaultContentRole, per-page roles) in the same commit"],"tags":["hugo","config","roles"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}