{"record":{"id":"2a8eac8e435ad027","repo":"projectdiscovery/nuclei","slug":"could-not-create-template-data-v","errorCode":null,"errorMessage":"could not create template data: %v","messagePattern":"could not create template data: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/js/devtools/bindgen/cmd/bindgen/main.go","lineNumber":51,"sourceCode":"}\n\nfunc process() error {\n\tmodules, err := generator.GetLibraryModules(dir)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"could not get library modules\")\n\t}\n\tif len(modules) == 0 && fileutil.FolderExists(dir) {\n\t\t// if no modules are found, then given directory is the module itself\n\t\ttargetModules = path.Base(dir)\n\t\tmodules = append(modules, targetModules)\n\t\tdir = filepath.Dir(dir)\n\t}\n\tfor _, module := range modules {\n\t\tlog.Printf(\"[module] Generating %s\", module)\n\n\t\tdata, err := generator.CreateTemplateData(filepath.Join(dir, module), \"github.com/projectdiscovery/nuclei/v3/pkg/js/libs/\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not create template data: %v\", err)\n\t\t}\n\n\t\tprefixed := \"lib\" + module\n\t\t// if !goOnly {\n\t\t// \terr = data.WriteJSTemplate(filepath.Join(generatedDir, \"js/\"+prefixed), module)\n\t\t// \tif err != nil {\n\t\t// \t\treturn fmt.Errorf(\"could not write js template: %v\", err)\n\t\t// \t}\n\t\t// }\n\t\terr = data.WriteGoTemplate(path.Join(generatedDir, \"go/\"+prefixed), module)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not write go template: %v\", err)\n\t\t}\n\t\t// disabled for now since we have static website for docs\n\t\t// err = data.WriteMarkdownLibraryDocumentation(path.Join(generatedDir, \"markdown/\"), module)\n\t\t// if err != nil {\n\t\t// \treturn fmt.Errorf(\"could not write markdown template: %v\", err)\n\t\t// }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/projectdiscovery/nuclei/blob/265b3a3dec374741614e342f813c10f8b38d2bb7/pkg/js/devtools/bindgen/cmd/bindgen/main.go#L33-L69","documentation":"bindgen's CreateTemplateData failed while processing a module directory under pkg/js/libs. It wraps the generator errors: 'could not parse directory', 'no packages found', or 'expected 1 package, got N'. The tool is a devtool used to regenerate the Go (and optionally JS) bindings for JS library modules.","triggerScenarios":"Running bindgen directly on a directory containing zero .go files (or only non-Go files), or several different packages; a build-tag split that makes parsePackageDir see extra package variants.","commonSituations":"Contributors adding a new lib module and invoking bindgen with the wrong path (repo root instead of the module dir); leftover experimental files with a different package clause in the module directory.","solutions":["Invoke via the supported entry point: make devtools-all (or make jsupdate-all) from the repo root, which passes correct paths","Ensure the target directory is a single Go package: exactly one package clause across its .go files and at least one non-test .go file","Remove or move stray files with a different package name out of the module directory"],"exampleFix":"# before\n./bindgen ./pkg/js/libs/\n\n# after\nmake devtools-all   # or: ./bindgen ./pkg/js/libs/<single-module>","handlingStrategy":"try-catch","validationCode":"# before running bindgen manually, verify one package per dir\ngo list ./pkg/js/libs/... >/dev/null && grep -h '^package ' pkg/js/libs/$MODULE/*.go | sort -u","typeGuard":null,"tryCatchPattern":"Check the error from CreateTemplateData, print the failing directory, and stop codegen — the wrapped message ('no packages found' vs 'expected 1 package, got N') tells you whether to add Go files or to split packages.","preventionTips":["Drive codegen through make devtools-all / jsupdate-all so paths are correct","Keep exactly one package per module directory under pkg/js/libs","Run go build ./pkg/js/... before regenerating"],"tags":["devtools","bindgen","code-generation"],"backgroundTag":null,"analyzedSha":"265b3a3dec374741614e342f813c10f8b38d2bb7","analyzedAt":"2026-08-15T20:05:51.855Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}