ent/ent · error

load package info: %w

Error message

load package info: %w

What it means

PkgPath uses golang.org/x/tools/go/packages.Load to resolve an import path for a target directory by loading the package there (searching up to 2 parent dirs). This error wraps a hard failure of packages.Load itself (driver invocation failed), as opposed to package-level compile errors which are handled separately. It means the go/packages driver could not run at all.

Source

Thrown at cmd/internal/base/packages.go:41

func PkgPath(config *packages.Config, target string) (string, error) {
	if config == nil {
		config = DefaultConfig
	}
	pathCheck, err := filepath.Abs(target)
	if err != nil {
		return "", err
	}
	var parts []string
	if _, err := os.Stat(pathCheck); os.IsNotExist(err) {
		parts = append(parts, filepath.Base(pathCheck))
		pathCheck = filepath.Dir(pathCheck)
	}
	// Try maximum 2 directories above the given
	// target to find the root package or module.
	for i := 0; i < 2; i++ {
		pkgs, err := packages.Load(config, pathCheck)
		if err != nil {
			return "", fmt.Errorf("load package info: %w", err)
		}
		if len(pkgs) == 0 || len(pkgs[0].Errors) != 0 {
			parts = append(parts, filepath.Base(pathCheck))
			pathCheck = filepath.Dir(pathCheck)
			continue
		}
		pkgPath := pkgs[0].PkgPath
		for j := len(parts) - 1; j >= 0; j-- {
			pkgPath = path.Join(pkgPath, parts[j])
		}
		return pkgPath, nil
	}
	return "", fmt.Errorf("root package or module was not found for: %s", target)
}

View on GitHub (pinned to 69d5d4deb1)

Solutions

  1. Run `go version` and `go list ./...` in the target dir to reproduce the underlying loader failure and fix it (install/upgrade Go).
  2. Ensure the command runs inside a valid module (go.mod exists) or set GO111MODULE appropriately.
  3. Clear a corrupt module/build cache if `go list` reports cache corruption (go clean -modcache).
  4. Fix GOFLAGS/GOENV if custom flags break `go list`; run `go env` to inspect.

Example fix

// before
$ entc generate  // outside any module -> go/packages driver fails
// after
$ cd myapp && go mod init example.com/myapp && go get entgo.io/ent && go run entc.go
Defensive patterns

Strategy: validation

Validate before calling

cmd := exec.Command("go", "list", "./...")
cmd.Dir = targetDir
if out, err := cmd.CombinedOutput(); err != nil {
    return fmt.Errorf("go list failed, go/packages will too: %v: %s", err, out)
}

Try / catch

pkgPath, err := base.PkgPath(pwd)
if err != nil {
    if strings.Contains(err.Error(), "load package info") {
        log.Fatalf("go/packages driver failed; check Go toolchain/module setup: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling base.PkgPath (used by entc to compute import paths) in an environment where `go list` fails outright: no go.mod/GOPATH setup, corrupted module cache, missing Go toolchain on PATH, or GOFLAGS/module errors that crash the loader.

Common situations: Running ent codegen outside a Go module; GO111MODULE mismatch; broken GOPATH or GOFLAGS; a go directive version newer than the installed toolchain; running in a sandbox without the go binary.

Related errors


AI-assisted analysis of ent/ent@69d5d4deb1 (2026-09-03). Data as JSON: /api/errors/53548cc7b98e9bbb. Report an issue: GitHub.