{"record":{"id":"bda034420e563aaa","repo":"gohugoio/hugo","slug":"resource-not-set","errorCode":null,"errorMessage":"resource not set","messagePattern":"resource not set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/esbuild/batch.go","lineNumber":1339,"sourceCode":"\t\tparamsJSON, err = json.Marshal(v.Params)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}\n\n\tif v.Export == \"\" {\n\t\tv.Export = defaults.defaultExport\n\t}\n\n\tcompiled := scriptOptions{\n\t\tResource:      v.Resource,\n\t\tExport:        v.Export,\n\t\tImportContext: resource.NewCachedResourceGetter(v.ImportContext),\n\t\tParams:        paramsJSON,\n\t}\n\n\tif compiled.Resource == nil {\n\t\treturn scriptOptions{}, fmt.Errorf(\"resource not set\")\n\t}\n\n\treturn compiled, nil\n}\n\ntype scriptRunnerTemplateContext struct {\n\topts   optionsGetSetter[scriptID, scriptOptions]\n\tImport string\n}\n\nfunc (s *scriptRunnerTemplateContext) Export() string {\n\treturn s.opts.Compiled().Export\n}\n\nfunc (c scriptRunnerTemplateContext) MarshalJSON() (b []byte, err error) {\n\treturn json.Marshal(&struct {\n\t\tID string `json:\"id\"`\n\t}{","sourceCodeStart":1321,"sourceCodeEnd":1357,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/js/esbuild/batch.go#L1321-L1357","documentation":"Thrown by scriptOptions.compileOptions when the decoded options map for a batch script lacks a non-nil Resource field. Resource (the Hugo resource to compile) is mandatory for every script entry in a batch.","triggerScenarios":"Calling js.Batcher and a script's option map either omits the Resource key or passes nil. The map is decoded via mapstructure.WeakDecode, so a missing key decodes to nil and trips the check at batch.go:1338.","commonSituations":"Template uses a wrong key name (e.g., src instead of resource); a partial that should supply the resource received nil from .Resources.Get but still forwarded the map; refactoring that dropped the Resource key.","solutions":["Ensure each script option map has Resource set to a non-nil Hugo resource.","Verify the template that assembles the options — confirm .Resources.Get returns non-nil before passing it on.","Print the options map with warnf \"%#v\" $opts to confirm the key/value at runtime."],"exampleFix":"// before\n{{ $opts := dict \"Export\" \"default\" }}\n{{ $batcher.Scripts $opts }}\n\n// after\n{{ $r := .Resources.Get \"main.ts\" }}\n{{ $opts := dict \"Resource\" $r \"Export\" \"default\" }}\n{{ $batcher.Scripts $opts }}","handlingStrategy":"validation","validationCode":"// Before passing options to the batcher, ensure Resource is non-nil.\nif opts[\"Resource\"] == nil {\n    return fmt.Errorf(\"batch script options missing required Resource: %#v\", opts)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always assert the resource lookup returned non-nil before assembling batch options.","In templates, use {{ with $r := .Resources.Get \"...\" }} ... {{ end }} so a nil resource short-circuits.","Document the required key name (Resource) prominently for batch authors."],"tags":["batch","template","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}