Go error: module found but does not contain package

Go resolved a module version successfully, but that version does not contain the requested package path. Check the selected release and nested modules.

go: module example.com/mod@v1.2.3 found, but does not contain package example.com/mod/cmd/tool
go: module example.com/mod@latest found (v1.4.0), but does not contain package example.com/mod/legacy

Fix it fast

Most likely: The package path belongs to another module boundary or another version than the one Go selected.

Confirm this is your error

Match the output and confirm you are troubleshooting the same failure.

go: module example.com/mod@v1.2.3 found, but does not contain package example.com/mod/cmd/tool
go: module example.com/mod@latest found (v1.4.0), but does not contain package example.com/mod/legacy

What This Error Means

Read this as a precise clue about which part of the workflow broke first. Once you know the failing layer, the fix path gets much shorter.

How to Fix It

The fastest fixes here come from checking the immediate failing layer before you change anything unrelated. Make one correction at a time and re-test from the same environment.

Wrong path:use the package path that exists in the selected release.

Nested module:require the nested module at its own module path and version.

Version mismatch:select a version containing the package and review the module-file changes.

Bad replacement:correct or remove the replace directive after confirming the replacement’s module boundary.

Removed package:migrate to the maintained replacement instead of pinning an unsupported release.

Why It Happens

There are usually a few repeatable root causes behind this message. Narrowing them down early prevents a lot of trial-and-error.

The import path is mistyped or comes from documentation for another release.

The package moved into a nested module with its own module path and version tags.

The selected version predates the package or was released after the package was removed.

A replace directive points to a local or remote module with a different directory layout.

The directory exists but contains no .go files.

Verify the Fix

Run go list <correct-package-path> and confirm it selects the expected package, and repeat the original build or tool installation and inspect the resulting module graph with go list -m all.

Inspect the selected version and module boundaries

Copy the module path, selected version, and requested package path from the error.

Run go list -m -json <module>@<version> and inspect the repository tree at that exact tag.

Look for nested go.mod files, moved packages, renamed command directories, directories with no .go files, and replace directives.

How Go maps a package path to a module

Go checks modules whose paths prefix the requested package path, then looks for the package in the selected source tree. The module may exist while the package does not. A nested go.mod creates a separate module and excludes that subtree from the parent module zip.

Prevent It From Coming Back

To prevent this, treat nested modules and import-path moves as release-contract changes, document package moves and the first and last versions that contain them, and test published tool installation paths and proxy contents before announcing a release.

Docs and source code

Go module query source

Current source for version-query and package-not-in-module diagnostics. - Source

Version queries select allowed versions and package queries confirm the selected module contains the requested package.

Go Modules Reference

Official reference for module files, version selection, proxies, private modules, checksums, workspaces, and vendoring. - Source

The go command uses module paths and versions to resolve, download, and authenticate dependencies.

Go package query tests

Current exact tests for package-not-in-module output, including replacement context. - Source

The tests report when a selected module version lacks the requested package path.

Need help or found a mistake? Contact RepoFlow support for questions.

Join our mailing list

Product updates, new tools, and practical guides from RepoFlow.