golang/go · error · PackageError

package %s not provided by module %s

Error message

package %s not provided by module %s

What it means

After loading all package arguments, a matched package has `pkg.Module == nil`, which happens for stdlib, cmd, and their vendored dependencies. The NoRoot install workflow requires every matched package to come from the resolved root module, so a nil-Module package is rejected.

Source

Thrown at src/cmd/go/internal/load/pkg.go:3481

	}

	// Since we are in NoRoot mode, the build list initially contains only
	// the dummy command-line-arguments module. Add a requirement on the
	// module that provides the packages named on the command line.
	if _, err := modload.EditBuildList(ld, ctx, nil, []module.Version{rootMod}); err != nil {
		return nil, fmt.Errorf("%s: %w", args[0], err)
	}

	// Load packages for all arguments.
	pkgs := PackagesAndErrors(ld, ctx, opts, patterns)

	// Check that named packages are all provided by the same module.
	for _, pkg := range pkgs {
		var pkgErr error
		if pkg.Module == nil {
			// Packages in std, cmd, and their vendored dependencies
			// don't have this field set.
			pkgErr = fmt.Errorf("package %s not provided by module %s", pkg.ImportPath, rootMod)
		} else if pkg.Module.Path != rootMod.Path || pkg.Module.Version != rootMod.Version {
			pkgErr = fmt.Errorf("package %s provided by module %s@%s\n\tAll packages must be provided by the same module (%s).", pkg.ImportPath, pkg.Module.Path, pkg.Module.Version, rootMod)
		}
		if pkgErr != nil && pkg.Error == nil {
			pkg.Error = &PackageError{Err: pkgErr}
			pkg.Incomplete = true
		}
	}

	matchers := make([]func(string) bool, len(patterns))
	for i, p := range patterns {
		if strings.Contains(p, "...") {
			matchers[i] = pkgpattern.MatchPattern(p)
		}
	}
	return pkgs, nil
}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Replace wildcard patterns (`...`) with exact package import paths from the target module.
  2. Verify module boundaries with `go list -m all` from a local checkout.
  3. Check for stdlib name collisions in the module's package list.
Defensive patterns

Strategy: validation

Validate before calling

// Avoid wildcards; resolve exact package paths first.
func expandPackages(mod, ver string) ([]string, error) {
    out, err := exec.Command("go", "list", "-m", "-json", mod+"@"+ver).Output()
    if err != nil { return nil, err }
    _ = out
    // enumerate packages explicitly rather than passing '...'
    return nil, nil
}

Prevention

When it happens

Trigger: A wildcard pattern like `example.com/...@v1.0.0` matches a path that resolves to a stdlib or cmd package; the module re-exports a name that collides with stdlib; the pattern accidentally covers a vendored stdlib dependency.

Common situations: Pattern matching unexpectedly hits a stdlib package; module path collides with a stdlib name; misconfigured module that vendored stdlib deps.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/30ec079c77e92de8. Report an issue: GitHub.