gohugoio/hugo · error

cannot use --renderToMemory with --destination

Error message

cannot use --renderToMemory with --destination

What it means

`hugo server` rejects a mutually exclusive flag combination: in-memory rendering (`--renderToMemory`) cannot coexist with an explicit `--destination`, because rendering to memory implies no on-disk output. The check reads both flags and returns a plain (unformatted) error.

Solutions

  1. Remove `--renderToMemory` when you need output written to `--destination`.
  2. Remove `--destination` when you want the memory-only server (the default for `hugo server`).
  3. Audit your wrapper script/alias for conflicting inherited flags.

Example fix

// before
// $ hugo server --renderToMemory --destination=public
// after
// $ hugo server --renderToMemory
Defensive patterns

Strategy: validation

Validate before calling

// Reject the conflicting flag pair before invoking Hugo.
func validateServerFlags(renderToMemory bool, destinationChanged bool) error {
  if renderToMemory && destinationChanged {
    return fmt.Errorf("cannot use --renderToMemory with --destination")
  }
  return nil
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Fires when `c.r.renderToMemory` is true AND the `destination` cobra flag exists and was explicitly set (`destinationFlag.Changed`).

Common situations: A developer copies `--renderToMemory` from a CI snippet while also passing `-d public`; mixing `server` flags intended for different workflows; alias scripts that always set both flags.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/74f4009852cbf794. Report an issue: GitHub.

Appendix: 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 52c9bd7908)