projectdiscovery/nuclei · error

could not create template data: %v

Error message

could not create template data: %v

What it means

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.

Source

Thrown at pkg/js/devtools/bindgen/cmd/bindgen/main.go:51

}

func process() error {
	modules, err := generator.GetLibraryModules(dir)
	if err != nil {
		return errors.Wrap(err, "could not get library modules")
	}
	if len(modules) == 0 && fileutil.FolderExists(dir) {
		// if no modules are found, then given directory is the module itself
		targetModules = path.Base(dir)
		modules = append(modules, targetModules)
		dir = filepath.Dir(dir)
	}
	for _, module := range modules {
		log.Printf("[module] Generating %s", module)

		data, err := generator.CreateTemplateData(filepath.Join(dir, module), "github.com/projectdiscovery/nuclei/v3/pkg/js/libs/")
		if err != nil {
			return fmt.Errorf("could not create template data: %v", err)
		}

		prefixed := "lib" + module
		// if !goOnly {
		// 	err = data.WriteJSTemplate(filepath.Join(generatedDir, "js/"+prefixed), module)
		// 	if err != nil {
		// 		return fmt.Errorf("could not write js template: %v", err)
		// 	}
		// }
		err = data.WriteGoTemplate(path.Join(generatedDir, "go/"+prefixed), module)
		if err != nil {
			return fmt.Errorf("could not write go template: %v", err)
		}
		// disabled for now since we have static website for docs
		// err = data.WriteMarkdownLibraryDocumentation(path.Join(generatedDir, "markdown/"), module)
		// if err != nil {
		// 	return fmt.Errorf("could not write markdown template: %v", err)
		// }

View on GitHub (pinned to 265b3a3dec)

Solutions

  1. Invoke via the supported entry point: make devtools-all (or make jsupdate-all) from the repo root, which passes correct paths
  2. 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
  3. Remove or move stray files with a different package name out of the module directory

Example fix

# before
./bindgen ./pkg/js/libs/

# after
make devtools-all   # or: ./bindgen ./pkg/js/libs/<single-module>
Defensive patterns

Strategy: try-catch

Validate before calling

# before running bindgen manually, verify one package per dir
go list ./pkg/js/libs/... >/dev/null && grep -h '^package ' pkg/js/libs/$MODULE/*.go | sort -u

Try / catch

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.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of projectdiscovery/nuclei@265b3a3dec (2026-08-15). Data as JSON: /api/errors/2a8eac8e435ad027. Report an issue: GitHub.