{"record":{"id":"0213c2e43ce1b9b3","repo":"gohugoio/hugo","slug":"resources-postprocess-cannot-be-used-in-a-deferred","errorCode":null,"errorMessage":"resources.PostProcess cannot be used in a deferred template","messagePattern":"resources\\.PostProcess cannot be used in a deferred template","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/tplimpl/templatetransform.go","lineNumber":453,"sourceCode":"\t\treturn\n\t}\n\n\tidArg = cmd.Args[0]\n\n\tif !c.isWithDefer(idArg) {\n\t\treturn\n\t}\n\n\tdeferArg := cmd.Args[1]\n\tcmd.Args = []parse.Node{idArg}\n\n\tl := doDefer.CopyList()\n\tn := l.Nodes[0].(*parse.ActionNode)\n\n\tinner := withNode.List.CopyList()\n\ts := inner.String()\n\tif strings.Contains(s, \"resources.PostProcess\") {\n\t\tc.err = errors.New(\"resources.PostProcess cannot be used in a deferred template\")\n\t\treturn\n\t}\n\tinnerHash := hashing.XxHashFromStringHexEncoded(s)\n\tdeferredID := tpl.HugoDeferredTemplatePrefix + innerHash\n\n\tc.deferNodes[deferredID] = inner\n\twithNode.List = l\n\n\tn.Pipe.Cmds[0].Args[1].(*parse.PipeNode).Cmds[0].Args[0].(*parse.StringNode).Text = deferredID\n\tn.Pipe.Cmds[0].Args[2] = deferArg\n}\n\nfunc (c *templateTransformContext) applyTransformationsToNodes(nodes ...parse.Node) {\n\tfor _, node := range nodes {\n\t\tc.applyTransformations(node)\n\t}\n}\n","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/tplimpl/templatetransform.go#L435-L471","documentation":"Thrown during template AST transformation when a deferred template (a `with`/partial marked with `defer`) contains a reference to resources.PostProcess (tpl/tplimpl/templatetransform.go:451-453). Hugo forbids PostProcess inside deferred execution because the deferred pass runs after the resources pipeline is already finalized, so deferred PostProcess could never take effect.","triggerScenarios":"Placing {{ (resources.Get \"x.css\" | resources.PostProcess) }} inside a template invoked via a `defer` argument (e.g. a deferred partial or a with/defer block).","commonSituations":"Refactoring a CSS/JS pipeline into a deferred partial for performance; using PostProcess in a header partial that is itself deferred; theme updates that introduced defer on partials that contain PostProcess.","solutions":["Move the resources.PostProcess call out of the deferred template into a non-deferred partial or the base template.","Remove the `defer` argument from the partial/with that wraps the PostProcess call.","If you need late CSS injection, use a non-deferred resource with appropriate fingerprinting instead of PostProcess."],"exampleFix":"// before (inside deferred partial)\n{{ partial \"head.html\" (dict \"defer\" true ...) }}\n  {{ resources.Get \"app.css\" | resources.PostProcess }}\n// after (PostProcess moved to non-deferred template)\n{{ partial \"head.html\" ... }}\n{{ resources.Get \"app.css\" | resources.PostProcess }}","handlingStrategy":"validation","validationCode":"{{/* Move resources.PostProcess out of any partial invoked with defer=true */}}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never place resources.PostProcess inside a deferred partial or with/defer block.","Audit partials for PostProcess before adding defer."],"tags":["template","resources","postprocess","defer","rendering","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}