Home >Backend Development >Golang >Why Does 'go build' Fail with 'module ... found but does not contain package' Error?

Why Does 'go build' Fail with 'module ... found but does not contain package' Error?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-13 16:51:02720browse

Why Does

"go module @latest found but does not contain package" Issue

When using Go modules for the first time, you may encounter the error message:

module github.com/mkideal/cli@latest found (v0.2.2), but does not contain package github.com/mkideal/cli
module github.com/mkideal/cli@latest found (v0.2.2), but does not contain package github.com/mkideal/cli/ext

This error occurs during go build and is not encountered during go get, indicating that the issue may not lie with the proxy settings or the Go module/package.

In this case, the root cause of the problem is a cached copy of the module metadata in the Go module cache. To resolve this, run the following command:

go clean -modcache

This command clears the Go module cache, allowing Go to download the latest metadata for the module and its dependencies. This ensures that the package versions and their contents are accurately reflected during the go build process.

The above is the detailed content of Why Does 'go build' Fail with 'module ... found but does not contain package' Error?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn