{"id":"74f4009852cbf794","repo":"gohugoio/hugo","slug":"cannot-use-rendertomemory-with-destination","errorCode":null,"errorMessage":"cannot use --renderToMemory with --destination","messagePattern":"cannot use --renderToMemory with --destination","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/server.go","lineNumber":603,"sourceCode":"\n\t\t\tif err := c.setServerInfoInConfig(); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tif !reloaded && c.fastRenderMode {\n\t\t\t\tc.withConf(func(conf *commonConfig) {\n\t\t\t\t\tconf.fs.PublishDir = hugofs.NewHashingFs(conf.fs.PublishDir, c.changeDetector)\n\t\t\t\t\tconf.fs.PublishDirStatic = hugofs.NewHashingFs(conf.fs.PublishDirStatic, c.changeDetector)\n\t\t\t\t})\n\t\t\t}\n\n\t\t\treturn nil\n\t\t},\n\t)\n\n\tdestinationFlag := cd.CobraCommand.Flags().Lookup(\"destination\")\n\tif c.r.renderToMemory && (destinationFlag != nil && destinationFlag.Changed) {\n\t\treturn fmt.Errorf(\"cannot use --renderToMemory with --destination\")\n\t}\n\tc.doLiveReload = !c.disableLiveReload\n\tc.fastRenderMode = !c.disableFastRender\n\tc.showErrorInBrowser = c.doLiveReload && !c.disableBrowserError\n\n\tif c.fastRenderMode {\n\t\t// For now, fast render mode only. It should, however, be fast enough\n\t\t// for the full variant, too.\n\t\tc.changeDetector = &fileChangeDetector{\n\t\t\t// We use this detector to decide to do a Hot reload of a single path or not.\n\t\t\t// We need to filter out source maps and possibly some other to be able\n\t\t\t// to make that decision.\n\t\t\tirrelevantRe: regexp.MustCompile(`\\.map$`),\n\t\t}\n\n\t\tc.changeDetector.PrepareNew()\n\n\t}","sourceCodeStart":585,"sourceCodeEnd":621,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/server.go#L585-L621","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nhugo server --renderToMemory -d public\n# after\nhugo server --renderToMemory","handlingStrategy":"validation","validationCode":"// before invoking hugo server\nif flags.RenderToMemory && flags.Destination != \"\" {\n    return errors.New(\"choose either --renderToMemory or --destination, not both\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["cli-flags","hugo-server","configuration"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}