gohugoio/hugo · error

imaging.webp.compression must be one of lossy or lossless, g

Error message

imaging.webp.compression must be one of lossy or lossless, got %q

What it means

WebpConfig.init checks that the effective WebP compression mode (own value, else global `imaging.compression`, else the default, lowercased) is in the compressionMethods set. WebP supports exactly two encoding modes — lossy and lossless — so any other string is rejected at config load.

Source

Thrown at resources/images/config.go:788

	}
	if c.Compression == "" {
		c.Compression = defaultCompression
	}
	if c.Quality == 0 {
		c.Quality = 75
	}

	c.Hint = strings.ToLower(c.Hint)
	c.Compression = strings.ToLower(c.Compression)

	if c.Hint != "" && !hints[c.Hint] {
		return fmt.Errorf("imaging.webp.hint must be one of picture, photo, drawing, icon, or text, got %q", c.Hint)
	}
	if c.Method < 0 || c.Method > 6 {
		return fmt.Errorf("imaging.webp.method must be between 0 and 6, got %d", c.Method)
	}
	if c.Compression != "" && !compressionMethods[c.Compression] {
		return fmt.Errorf("imaging.webp.compression must be one of lossy or lossless, got %q", c.Compression)
	}
	if c.Quality < 1 || c.Quality > 100 {
		return fmt.Errorf("imaging.webp.quality must be between 1 and 100 inclusive, got %d", c.Quality)
	}
	return nil
}

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Set the compression value to exactly "lossy" or "lossless".
  2. Remove the key to fall back to the default.
  3. Use `imaging.webp.quality` to tune lossy output size rather than inventing compression values.

Example fix

# before
[imaging.webp]
compression = "auto"
# after
[imaging.webp]
compression = "lossy"
Defensive patterns

Strategy: validation

Validate before calling

if c := cfg.Imaging.WebP.Compression; c != "" && c != "lossy" && c != "lossless" {
    return fmt.Errorf("webp compression must be lossy or lossless, got %q", c)
}

Prevention

When it happens

Trigger: Setting `[imaging.webp] compression` or the global `[imaging] compression` to anything other than "lossy" or "lossless" in hugo.toml/yaml/json.

Common situations: Typos like "lossles"/"loseless", numeric compression levels carried over from PNG settings, or values like "auto"/"mixed" from other WebP tooling.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/a6e0cfa65261bc46.json. Report an issue: GitHub ↗.