parsing go.mod: unexpected module path "golang.org/x/lint" - go

I have a package that I've uploaded to Github and am I am go getting the package on another server and keep getting the error:
go: github.com/golang/lint#v0.0.0-20190313153728-d0100b6bd8b3: parsing go.mod: unexpected module path "golang.org/x/lint"
I've deleted go.mod, go.sum and the vendor directory and updated all packages using
go get -u ./...
golang.org/x/lint is not in go.mod or go.sum or vendor directory yet I still get the error when trying to go get the package on my other server.

Note that, May 2021 (two years later) x/lint is fully deprecated. See issue 38968 and CL 318190.
Your error was seen in issue 32412 (related to issue 27900).
And go get -u has been fixed (CL 174099 "make get -u upgrade only modules providing packages")

Related

Golang grpc go.mod issue

Hi guys does anyone would know what is the issue with this package:
go: loading module retractions for github.com/googleapis/gax-go/v2#v2.0.1: parsing go.mod: go.mod:8:2: require google.golang.org/genproto: version "b98a9ff5e252" invalid: must be of the form v1.2.3
after doing go get -u ./... or how to work around to fix this ?
The go.mod file of the module you are trying to import is broken. As the message you posted says, the version number should start with "v" (see here)
It seems that the module was broken by a bot https://github.com/googleapis/gax-go/commit/735836c34b8124d657958d469998865569e14742
The solution would be to revert the commit on the googleapis/gax-go repository.

What does "inconsistent vendoring" mean in Go?

I'm getting this inconsistent vendoring error and I'm a total Go newbie. Can anyone explain to me how go.mod interacts with vendor/modules.txt? I found this question helpful, and now I'm wondering if I should even have a vendor directory. Would that be created by running go mod vendor? I inherited this project and it already has the vendor directory in git.
Here's the relevant part of my go.mod file -
module mymodule
go 1.17
require (
gopkg.in/redis.v5 v5.2.9
)
And then the related error message:
go: inconsistent vendoring
gopkg.in/redis.v5#v5.2.9: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
In vendor/modules.txt I have:
#gopkg.in/redis.v5 v5.2.9
gopkg.in/redis.v5
gopkg.in/redis.v5/internal
gopkg.in/redis.v5/internal/consistenthash
gopkg.in/redis.v5/internal/hashtag
gopkg.in/redis.v5/internal/pool
gopkg.in/redis.v5/internal/proto
For what it's worth I'm getting this error for every dependency in my go.mod file, I just included the one about redis.
go.mod and vendor/modules.txt (if present) must be in sync.
Whenever go.mod changes and there is a vendor directory, go mod vendor needs to be run to update the contents of the vendor directory.
All direct dependencies (not marked // implicit in go.mod) are "explicit" and marked accordingly in vendor/modules.txt starting from Go 1.14.
After running go mod vendor notice the new line ## explicit added after the package reference:
#gopkg.in/redis.v5 v5.2.9
## explicit
. . .
Just to add to #rustyx's answer, in order to fix this error, I deleted the vendor folder and then I ran again go mod vendor, and the error disappeared.
For me updating the version solved the issue. I was running go1.16 and I updated to go1.18.2. Before the update I tried go mod vendor and also updating the modules.txt didn't work then, I started ignoring the vendor directory by running
go build -mod=mod to build the application or go run -mod=mod main.go to run the main.go file

go module #latest found but does not contain package

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:
prepare /tmp/015-file from https://github.com/mkideal/cli/blob/master/_examples/015-file
do go mod init
then 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
Try clearing cache:
go clean -modcache
For more info on how this command works, use go help clean
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.
Update to go version go1.14.3 linux/amd64
Clear go module cache
don't know which one solved the problem (or both), now AOK.
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.
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
I had a similar problem. In my case the package name was not matching the name of the folder it resided in.

go get -u github.com/onsi/ginkgo/ginkgo starts throwing error all of a sudden

When I run go get -u github.com/onsi/ginkgo/ginkgo
till yesterday I had no issues. Specifically with fsnotify the output was like below
00:52:08 go: downloading gopkg.in/fsnotify.v1 v1.4.7
00:52:08 go: extracting gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
00:52:08 go: extracting gopkg.in/fsnotify.v1 v1.4.7
Now I see this error while executing same command
11:50:39 go: gopkg.in/fsnotify.v1#v1.4.8: go.mod has non-....v1 module path "github.com/fsnotify/fsnotify" at revision v1.4.8
11:50:39 go get: error loading module requirements
What might have gone wrong here
Some module in the transitive dependencies of github.com/onsi/ginkgo/ginkgo added a requirement on some version of gopkg.in/fsnotify.v1, which resolves to the repository hosted at github.com/fsnotify/fsnotify.
However, the go.mod file in that repository declares its canonical import path to be github.com/fsnotify/fsnotify, not gopkg.in/fsnotify.v1.
If you are using Go 1.14, the rest of the error message (which seems to be truncated) should tell you exactly which dependency is using the non-canonical path. The long-term fix is to move that dependency over to the canonical path and upgrade your other dependencies such that gopkg.in/fsnotify.v1 is no longer required.

go.mod has post-v0 module path "git.example.com/owner/repo/v3" at revision ...?

My coworker pushed a tag v3.0.1 before updating go.mod to have /v3 suffix (https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher). I have updated module path (go.mod) and all import paths (*.go) to fix it, tagged as v3.0.2.
Now the problem is:
go get -v git.example.com/owner/repo#v3.0.2
go: finding git.example.com/owner/repo v3.0.2
go: git.example.com/owner/repo#v0.0.0-20190722053407-d85c4f69ad17: go.mod has post-v0 module path "git.example.com/owner/repo/v3" at revision
d85c4f69ad17
Found this: go build keeps complaining that: go.mod has post-v0 module path
So, I deleted both v3.0.0 and v3.0.1 tags, pointed it to the latest commit, re-pushed but the problem still stand.
I noticed that go.mod still refered to the old version as an indirect dependency:
require (
git.example.com/owner.repo v0.1.2 // indirect
Even if I changed it to /v3 v3.0.2 it will be restored to v0.1.12 automatically.
Why?
Did I miss something?
Tue Jul 23 05:54:56 +07 2019
rm go.*
go mod init git.example.com/dependent/project
go mod tidy
and go.mod is updated correctly now:
require (
- git.example.com/owner/repo v0.1.2
+ git.example.com/owner/repo/v3 v3.0.2
but go get -v git.example.com/owner/repo#v3.0.2 still returned the error:
go: finding git.example.com/owner/repo v3.0.2
go: git.example.com/owner/repo#v0.0.0-20190722053407-d85c4f69ad17: go.mod has post-v0 module path "git.example.com/owner/repo/v3" at revision
d85c4f69ad17
(d85c4f69ad17 is the latest commit in master)
I noticed that there are both v0.1.2 and v3.0.2 in go.sum:
git.example.com/owner/repo v0.1.2 h1:mCGJEmyrFDTCGkRfUIORpqdrNkSONQ6K+AcTNgxqveY=
git.example.com/owner/repo v0.1.2/go.mod h1:FfUKnyPrARCtAXQZ3BQVJI7h2eJ0UpQBMLg4bNs4Kdc=
git.example.com/owner/repo/v3 v3.0.2 h1:mJtDKLeiP8vMRSZo08i/k/KDbIoZTlKW2aWu7DUBvMM=
git.example.com/owner/repo/v3 v3.0.2/go.mod h1:64LE0ts0Lk9InIQyhPYGmnxs6LZIl6H4Iorl1EXfqxo=
Please pay attention to my go get command:
go get -v git.example.com/owner/repo#v3.0.2
It should be:
go get -v git.example.com/owner/repo/v3#v3.0.2
for example you can replace repository with this hack: https://github.com/golang/go/wiki/Modules
require {
...
}
replace git.example.com/owner.repo v0.1.2 => git.example.com/owner.repo v3.0.2
or you can use go get at the commit hash you want:
go get git.example.com/owner.repo#af044c0995fe
go get will correctly update the dependency files (go.mod, go.sum).
For more information: https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies
or for last example you should clean cache
remove go.mod and go.sum
go cache clean
go mod vendor
Expanding on the answer from #quanta...
You are doing:
go get -v git.example.com/owner/repo#v3.0.2
Because it is a v3 module, the go get command should include a /v3 before the #:
go get -v git.example.com/owner/repo/v3#v3.0.2
Once a v3.x.y package is a module with its own go.mod, then whenenver you are operating with modules enabled, you pretty much always include the /v3 whenever you reference the v3.x.y module, including in:
arguments to go get on the command line
import statements in .go code for the consumer
require statements in a consumer's go.mod
replace or exclude statements in a consumer's go.mod
the module line of the v3 module's go.mod file
internal import statements in .go code inside the v3 module importing other packages in the v3 module
etc.
One way to think about it is that the module's name is now effectively git.example.com/owner/repo/v3, where its name includes the trailing /v3.
If you are a consumer of a vN module and need to update your import paths in your .go files to include the vN, then
github.com/marwan-at-work/mod is a commonly used tool from the community that automates adding the /vN in all the required spots. Separately, it also automates placing the /vN in all the required spots if you are a module author for a v2+ module.
From the "Semantic Import Versioning" section of the Go modules wiki:
If the module is version v2 or higher, the major version of the module must be included as a /vN at the end of the module paths used in go.mod files (e.g., module github.com/my/mod/v2, require github.com/my/mod/v2 v2.0.0) and in the package import path (e.g., import "github.com/my/mod/v2/mypkg").
I may have had a similiar issue where I updated a module to use the /v2 import path but go getting the module always returned an error about invalid go.mod
The solution was to go get -u github.com/<me>/<pkg>/v2

Resources