gohugoio/hugo · error
failed to create baseURL from
Error message
failed to create baseURL from %q: %s
What it means
When setting server info per language, Hugo constructs a `urls.BaseURL` from the resolved base URL string via `urls.NewBaseURLFromString`. This wraps a parse failure for that URL; `%q` is the offending string and `%s` the parse error.
Solutions
- Set a valid, absolute `baseURL` (e.g. `https://example.com/`) in `hugo.toml`.
- URL-encode any special characters in the baseURL.
- For multihost, verify every language's `baseURL` is individually valid.
- Re-run `hugo server` after fixing; the value is re-parsed on startup.
Example fix
// before baseURL = "my site.example" // after baseURL = "https://my-site.example/"
Defensive patterns
Strategy: validation
Validate before calling
import "net/url"
func validateBaseURL(s string) error {
if s == "" { return fmt.Errorf("empty baseURL") }
u, err := url.Parse(s)
if err != nil { return err }
if u.Scheme == "" || u.Host == "" { return fmt.Errorf("baseURL must be absolute: %q", s) }
return nil
} Type guard
null
Try / catch
null
Prevention
- Always set an absolute `baseURL` (scheme + host) in `hugo.toml`.
- URL-encode special characters in the baseURL.
- In multihost setups, validate each language's baseURL individually.
When it happens
Trigger: Fires after `fixURL` produces a string that `NewBaseURLFromString` cannot accept — typically a baseURL with control characters, an unparseable scheme, or empty after massaging. Triggered for each language config entry during `setServerInfoInConfig`.
Common situations: A `baseURL` in `hugo.toml` containing spaces or non-ASCII without encoding; a `--baseURL` flag with a malformed value; a multihost setup where one language's `baseURL` is invalid.
Related errors
- cannot use --renderToMemory with --destination
- failed to split baseURL hostport
- --appendPort=false not supported when in multihost mode
- cardinalityThreshold threshold must be between 0 and 100
- expected a map, a slice with an even number of elements, or…
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/463dd1403ded3723.
Report an issue: GitHub.
Appendix: source
Thrown at commands/server.go:651
panic("no server ports set")
}
return c.withConfE(func(conf *commonConfig) error {
for i, language := range conf.configs.Languages {
isMultihost := conf.configs.IsMultihost
var serverPort int
if isMultihost {
serverPort = c.serverPorts[i].p
} else {
serverPort = c.serverPorts[0].p
}
langConfig := conf.configs.LanguageConfigMap[language.Lang]
baseURLStr, err := c.fixURL(langConfig.BaseURL, c.r.baseURL, serverPort)
if err != nil {
return err
}
baseURL, err := urls.NewBaseURLFromString(baseURLStr)
if err != nil {
return fmt.Errorf("failed to create baseURL from %q: %s", baseURLStr, err)
}
baseURLLiveReload := baseURL
if c.liveReloadPort != -1 {
baseURLLiveReload, _ = baseURLLiveReload.WithPort(c.liveReloadPort)
}
langConfig.C.SetServerInfo(baseURL, baseURLLiveReload, c.serverInterface)
}
return nil
})
}
func (c *serverCommand) getErrorWithContext() any {
buildErr := c.errState.buildErr()
if buildErr == nil {
return nil
}View on GitHub (pinned to 52c9bd7908)