golang/go · warning

not a known dependency

Error message

not a known dependency

What it means

When listing modules in non-vendor mode and a path resolves to version "none" (not in the build list), and the user is not asking for the list of available versions, the go command marks the module with this Error rather than silently omitting it. It means: nothing in the current module graph matches that path.

Source

Thrown at src/cmd/go/internal/modload/list.go:279

			if v != "none" {
				mods = append(mods, moduleInfo(ld, ctx, rs, module.Version{Path: arg, Version: v}, mode, reuse))
			} else if cfg.BuildMod == "vendor" {
				// In vendor mode, we can't determine whether a missing module is “a
				// known dependency” because the module graph is incomplete.
				// Give a more explicit error message.
				mods = append(mods, &modinfo.ModulePublic{
					Path:  arg,
					Error: modinfoError(arg, "", errors.New("can't resolve module using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)")),
				})
			} else if mode&ListVersions != 0 {
				// Don't make the user provide an explicit '@latest' when they're
				// explicitly asking what the available versions are. Instead, return a
				// module with version "none", to which we can add the requested list.
				mods = append(mods, &modinfo.ModulePublic{Path: arg})
			} else {
				mods = append(mods, &modinfo.ModulePublic{
					Path:  arg,
					Error: modinfoError(arg, "", errors.New("not a known dependency")),
				})
			}
			continue
		}

		var matches []module.Version
		for _, m := range mg.BuildList() {
			if match(m.Path) {
				if !matchedModule[m] {
					matchedModule[m] = true
					matches = append(matches, m)
				}
			}
		}

		if len(matches) == 0 {
			fmt.Fprintf(os.Stderr, "warning: pattern %q matched no module dependencies\n", arg)
		}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Add the dependency: `go get <path>`.
  2. Query with an explicit version: `go list -m <path>@latest`.
  3. Check the path for typos against go.mod.

Example fix

# before
$ go list -m exampple.com/foo   # typo
# Error: not a known dependency

# after
$ go list -m example.com/foo@latest
Defensive patterns

Strategy: validation

Validate before calling

// Confirm a module is a known dependency before listing it.
func isKnownDep(modPath string) bool {
    b, err := os.ReadFile("go.mod")
    if err != nil { return false }
    return bytes.Contains(b, []byte(modPath))
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: `go list -m <path>` with no @version, where <path> is not a dependency of the main module and BuildMod is not vendor.

Common situations: Typos in the path; querying a transitive dependency that isn't selected; checking if something is required before adding it.

Related errors


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