gohugoio/hugo · error
media type %q not found
Error message
media type %q not found
What it means
Thrown by ResourceConfig.Compile when a page resource explicitly sets Content.MediaType but mediaTypes.GetByType returns found=false, meaning that media type string is not registered. This applies to resources (images, data files, etc.) declared in front matter / page resources, not the page content itself.
Source
Thrown at resources/page/pagemeta/page_frontmatter.go:510
return nil
}
func (rc *ResourceConfig) Compile(basePath string, fim hugofs.FileMetaInfo, conf config.AllProvider, mediaTypes media.Types) error {
if rc.Params != nil {
hmaps.PrepareParams(rc.Params)
}
// Note that NormalizePathStringBasic will make sure that we don't preserve the unnormalized path.
// We do that when we create resources from the file system; mostly for backward compatibility,
// but also because people tend to use the filename to name their resources (with spaces and all),
// and this isn't relevant when creating resources from an API where it's easy to add textual meta data.
rc.Path = paths.NormalizePathStringBasic(path.Join(basePath, rc.Path))
rc.PathInfo = conf.PathParser().Parse(files.ComponentFolderContent, rc.Path)
if rc.Content.MediaType != "" {
var found bool
rc.ContentMediaType, found = mediaTypes.GetByType(rc.Content.MediaType)
if !found {
return fmt.Errorf("media type %q not found", rc.Content.MediaType)
}
}
var sitesMatrixFile sitesmatrix.VectorStore
if fim != nil {
sitesMatrixFile = fim.Meta().SitesMatrix
}
rc.SitesMatrix = buildSitesMatrixFromSitesConfig(
conf,
sitesMatrixFile,
rc.Sites,
)
rc.SitesComplements = buildSitesComplementsFromSitesConfig(
conf,
fim.Meta(),
rc.Sites,View on GitHub (pinned to 52c9bd7908)
Solutions
- Register the media type under [mediaTypes] in your config.
- Correct the mediaType string to a known registered type.
- Omit mediaType and let Hugo infer it from the resource's file extension.
Example fix
# before
---
resources:
- src: data.custom
mediaType: application/x-custom
---
# after (also add to config)
[mediaTypes."application/x-custom"]
suffixes = ["custom"] Defensive patterns
Strategy: validation
Validate before calling
if _, found := mediaTypes.GetByType(rc.Content.MediaType); rc.Content.MediaType != "" && !found {
return fmt.Errorf("media type %q not registered", rc.Content.MediaType)
} Try / catch
if err := rc.Compile(basePath, fim, conf, mediaTypes); err != nil {
return fmt.Errorf("resource compile: %w", err)
} Prevention
- Register custom media types under [mediaTypes] before using them for resources.
- Prefer letting Hugo infer mediaType from the resource extension.
- Validate mediaType strings against registered types.
When it happens
Trigger: A page resource in front matter sets 'mediaType: application/x-foo' where that type is not defined under [mediaTypes].
Common situations: Referencing a custom media type for a resource without registering it, or a typo in the mediaType value for a resource declaration.
Related errors
- failed to resolve media type for %q
- failed to decode sites from front matter: %w
- failed to resolve media type for suffix %q
- failed to decode page map: %w
- failed to resolve output formats %v: %w
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/57c312e0494634ca.
Report an issue: GitHub.