gohugoio/hugo · error
cannot use --renderToMemory with --destination
Error message
cannot use --renderToMemory with --destination
What it means
Hugo's `hugo server` command validates its flag combination during PreRun. `--renderToMemory` serves the rendered site from an in-memory filesystem, so writing to a disk destination is contradictory; if the `--destination` flag was explicitly changed while `renderToMemory` is set, Hugo fails fast rather than silently ignoring one of them.
Source
Thrown at commands/server.go:603
if err := c.setServerInfoInConfig(); err != nil {
return err
}
if !reloaded && c.fastRenderMode {
c.withConf(func(conf *commonConfig) {
conf.fs.PublishDir = hugofs.NewHashingFs(conf.fs.PublishDir, c.changeDetector)
conf.fs.PublishDirStatic = hugofs.NewHashingFs(conf.fs.PublishDirStatic, c.changeDetector)
})
}
return nil
},
)
destinationFlag := cd.CobraCommand.Flags().Lookup("destination")
if c.r.renderToMemory && (destinationFlag != nil && destinationFlag.Changed) {
return fmt.Errorf("cannot use --renderToMemory with --destination")
}
c.doLiveReload = !c.disableLiveReload
c.fastRenderMode = !c.disableFastRender
c.showErrorInBrowser = c.doLiveReload && !c.disableBrowserError
if c.fastRenderMode {
// For now, fast render mode only. It should, however, be fast enough
// for the full variant, too.
c.changeDetector = &fileChangeDetector{
// We use this detector to decide to do a Hot reload of a single path or not.
// We need to filter out source maps and possibly some other to be able
// to make that decision.
irrelevantRe: regexp.MustCompile(`\.map$`),
}
c.changeDetector.PrepareNew()
}View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Drop `--destination`/`-d` when using `--renderToMemory` — the memory filesystem serves the site directly.
- If you need output on disk (e.g. for another tool to read), drop `--renderToMemory` instead.
- Check shell aliases, Makefiles, and npm scripts for a hardcoded `-d` flag.
Example fix
# before hugo server --renderToMemory -d public # after hugo server --renderToMemory
Defensive patterns
Strategy: validation
Validate before calling
// before invoking hugo server
if flags.RenderToMemory && flags.Destination != "" {
return errors.New("choose either --renderToMemory or --destination, not both")
} Prevention
- Treat --renderToMemory and --destination as mutually exclusive in your wrapper scripts
- Validate flag combinations before spawning the hugo process
- Default dev workflows to --renderToMemory alone; only set --destination for disk builds
When it happens
Trigger: Running `hugo server --renderToMemory --destination <dir>` (or with `-d`). The check fires only when the cobra `destination` flag is marked Changed, i.e. explicitly passed on the command line while `c.r.renderToMemory` is true.
Common situations: Copy-pasting a build command (`hugo -d public`) and adding `server --renderToMemory` for live preview; CI scripts or Makefiles that always append `--destination`; shell aliases that bake in `-d` and later add `--renderToMemory` for speed.
Related errors
- failed to create baseURL from %q: %s
- --appendPort=false not supported when in multihost mode
- failed to parse root certificate
- failed to parse certificate PEM
- failed to parse certificate: %v
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/74f4009852cbf794.json.
Report an issue: GitHub ↗.