projectdiscovery/nuclei · error
expected 1 package, got %d
Error message
expected 1 package, got %d
What it means
parsePackageDir returned more than one package for the directory passed to CreateTemplateData, but bindgen processes exactly one module package at a time. Multiple package clauses (or package variants behind build tags) in the same directory trigger it.
Source
Thrown at pkg/js/devtools/bindgen/generator.go:129
}
return modules, nil
}
// CreateTemplateData creates a TemplateData structure from a directory
// of go source code.
func CreateTemplateData(directory string, packagePrefix string) (*TemplateData, error) {
fmt.Println(directory)
fset := token.NewFileSet()
pkgs, err := parsePackageDir(fset, directory)
if err != nil {
return nil, errors.Wrap(err, "could not parse directory")
}
if len(pkgs) == 0 {
return nil, errors.New("no packages found")
}
if len(pkgs) != 1 {
return nil, fmt.Errorf("expected 1 package, got %d", len(pkgs))
}
config := &types.Config{
Importer: importer.ForCompiler(fset, "source", nil),
}
var packageName string
var pkgMain *parsedPackage
var files []*ast.File
for name, pkg := range pkgs {
packageName = name
pkgMain = pkg
break
}
filenames := make([]string, 0, len(pkgMain.files))
for filename := range pkgMain.files {
filenames = append(filenames, filename)
}
sort.Strings(filenames)View on GitHub (pinned to 265b3a3dec)
Solutions
- Run grep -h '^package ' <dir>/*.go | sort -u — it must yield exactly one name
- Fix or move offending files so the directory holds a single package
- Re-run bindgen / make devtools-all
Example fix
# before: dir contains package smb and package smbhelper # after: all files in dir declare: package smb
Defensive patterns
Strategy: validation
Validate before calling
out, err := exec.Command("sh", "-c", "grep -h '^package ' "+dir+"/*.go | sort -u").Output()
if err != nil || strings.Count(strings.TrimSpace(string(out)), "\n") != 0 {
log.Fatalf("directory must contain exactly one package: %s", out)
} Try / catch
Catch the error from CreateTemplateData; when the wrapped text says 'expected 1 package', stop and reconcile package clauses in the directory rather than retrying.
Prevention
- One package per directory under pkg/js/libs — no exceptions
- Watch for rename leftovers: old files keeping the previous package line
- Add a CI check that validates single-package dirs before codegen
When it happens
Trigger: A directory under pkg/js/libs containing files with two different package names (e.g. package smb and package smbutil), or generated/abandoned files from a rename that kept the old package clause.
Common situations: Copy-pasting a new lib file and forgetting to update its package line; leftovers after renaming a module; adding an 'internal' helper file with a different package name into the module dir.
Related errors
- could not create template data: %v
- could not write go template: %v
- could not create entity parser: %s
- could not parse entities: %s
- could not scrape and create new object: %s
AI-assisted analysis of projectdiscovery/nuclei@265b3a3dec (2026-08-15).
Data as JSON: /api/errors/6b8f83ec0ed5b81c.
Report an issue: GitHub.