Reputation: 23084
I'm trying to make use of go module for the first time. What exactly the following error message is telling me?
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
It happens during go build
, whereas go get
is just fine:
$ go get -v github.com/mkideal/cli
go: github.com/mkideal/cli upgrade => v0.2.2
but not go get -v ./...
, which gave me the same error as above. My proxy setting looks OK:
$ go env | grep GOPROXY
GOPROXY="https://proxy.golang.org,direct"
Is it a problem of the go module/package I'm trying to use, or my own code's problem? -- I took a look at https://github.com/mkideal/cli/blob/master/go.mod and it seems fine to me.
See the following update for details.
How can I overcome the situation? (I'm getting the same error message for my own repo as well)
UPDATE:
Here is the full log how I'm getting the above error:
/tmp/015-file
from https://github.com/mkideal/cli/blob/master/_examples/015-filego mod init
go build
Now the details:
$ cd /tmp/015-file
$ GO111MODULE=on
$ go mod init github.com/mkideal/cli/015-file
go: creating new go.mod: module github.com/mkideal/cli/015-file
$ cat go.mod
module github.com/mkideal/cli/015-file
go 1.14
$ go build
go: finding module for package github.com/mkideal/cli
go: finding module for package github.com/mkideal/cli/ext
main.go:6:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not contain package github.com/mkideal/cli
main.go:7:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not contain package github.com/mkideal/cli/ext
$ go get -v github.com/mkideal/cli
go: github.com/mkideal/cli upgrade => v0.2.2
$ go get -v ./...
go: finding module for package github.com/mkideal/cli
go: finding module for package github.com/mkideal/cli/ext
go: finding module for package github.com/mkideal/cli
go: finding module for package github.com/mkideal/cli/ext
main.go:6:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not contain package github.com/mkideal/cli
main.go:7:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not contain package github.com/mkideal/cli/ext
$ go version
go version go1.14.1 linux/amd64
Upvotes: 79
Views: 109383
Reputation: 11
The problem may be with version of your lib that your trying to include. If you lib have tag for example v2.X.X but the project structure of your lib doesn't have directory named v2 so this may cause that error
Upvotes: 1
Reputation: 21
I had the same issue, but none of the above solutions worked. The clue for me was the error output:
module github.com/ACCOUNT/REPO@latest found (v1.0.1), but does not contain package github.com/ACCOUNT/REPO/module
But I hadn't tagged my git repo. The solution was to tag my release higher than reported in the error:
$ git tag v1.0.2
$ git push origin v1.0.2
$ go mod tidy
Upvotes: 1
Reputation: 350
If you have a go package inside a go package, then to import the "inside" go package you have to use replace till that "inside" go package.
Ex: Assume this is the folder structure for the package you are importing
dir1/
go.mod
go.sum
main.go
dir2/
go.mod
go.sum
main.go
In your file.go you are importing dir2
package file
import (
"github.com/dir1/dir2"
)
Then this replace directive in your go.mod file is incorrect
replace (
github.com/dir1 => ../dir1
)
Instead you must replace till the dir2 path like below
replace (
github.com/dir1/dir2 => ../dir1/dir2
)
Upvotes: 3
Reputation: 2097
I faced the same error but with a different scenario and solution.
Scenario: I was getting this error:
go.opentelemetry.io/otel/semconv: module go.opentelemetry.io/otel@latest found (v1.13.0), but does not contain package go.opentelemetry.io/otel/semconv
Reason: It was because go.opentelemetry.io/otel/semconv
existed in old version of go.opentelemetry.io/otel
but it doesn't now.
Solution: I should've looked for a place which I wrongly Imported go.opentelemetry.io/otel/semconv
instead of go.opentelemetry.io/otel/semconv/vX.Y.Z
Replacing the imported package fixes the problem in many cases but my problem was a little bit deeper,
I hadn't imported go.opentelemetry.io/otel/semconv
directly but one of my deprecated third-party packages (Otel Jaeger) did, so I removed the third-party package and this fixed my issue.
TL;DR: I recommend people facing this issue reconsider using deprecated packages and also have a look if they've imported the correct packages.
Upvotes: 5
Reputation: 575
I had a similar problem. In my case the package
name in go.mod
was not matching the name of the folder it resided in.
Upvotes: 6
Reputation: 407
I was having this issue with https://pkg.go.dev/github.com/vmware-labs/yaml-jsonpath/pkg/yamlpath because I was trying to it as yamlpath "github.com/vmware-labs/yaml-jsonpath
I was getting errors like
go: finding module for package github.com/vmware-labs/yaml-jsonpath
example.com/template-test/poc imports
github.com/vmware-labs/yaml-jsonpath: module github.com/vmware-labs/yaml-jsonpath@latest found (v0.3.2), but does not contain package github.com/vmware-labs/yaml-jsonpath
no required module provides package github.com/vmware-labs/yaml-jsonpath; to add it:
go get github.com/vmware-labs/yaml-jsonpath
@Martin Meli's answer helped me.
I needed to import github.com/vmware-labs/yaml-jsonpath/pkg/yamlpath
instead. That resolved the issue.
$ go build
$ #...
$ go get github.com/vmware-labs/yaml-jsonpath/pkg/[email protected]
go: downloading github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960
Upvotes: 4
Reputation: 6562
Cleaning up Golang caches should do the job:
go clean -cache
go clean -modcache
For more info on how this command works, use go help clean
.
If you have similar problems with your test environment, run go clean -testcache
.
Upvotes: 22
Reputation: 303
In my case, go.mod files were under src, after moving the go.mod file into one level up, then it works
Refer the Samples below,
directory structure when "package not found" error
dir1/src/
main.go
go.mod
go.sum
directory structure after fix
dir1/
go.mod
go.sum
src/
main.go
Upvotes: 6
Reputation: 704
Try clearing cache:
go clean -modcache
For more info on how this command works, use go help clean
Upvotes: 53
Reputation: 91
In my case cleaning cache didn't help.
Running go install
in a project root printed no Go files in ...
and that was the root cause, in the same time running go install gitlab.com/....
printed info about a missing package.
What had to be done was creating a go file in a project root directory with main
function.
Upvotes: 8
Reputation: 31
I had the same error, but in my case I was attempting to import a module that made available only resource files, and no go pkgs. Adding an empty go file in the module with a package declaration solved it.
Upvotes: 3
Reputation: 23084
go version go1.14.3 linux/amd64
don't know which one solved the problem (or both), now AOK.
Upvotes: 4