What version of Go are you using (go version)?
$ go version
go version
go version go1.20.1 darwin/amd64
What did you do?
-- go.mod --
module w
go 1.20
require gopkg.in/yaml.v2 v2.4.0
replace gopkg.in/yaml.v2 => gopkg.in/yaml.v3 v3.0.0
-- main.go --
package main
import "gopkg.in/yaml.v2"
func main() {
var t struct{ A string }
_, _ = yaml.Marshal(&t)
}
And run go build
Note: the go.mod isn't tidy.
What did you expect to see?
Error related to mismatching module paths. (gopkg.in/yaml.v2 vs gopkg.in/yaml.v3)
What did you see instead?
No error.
go list sees the replacement.
$ go list -f '{{.Module}}' gopkg.in/yaml.v2
gopkg.in/yaml.v2 v2.4.0 => gopkg.in/yaml.v3 v3.0.0
go mod tidy adds gopkg.in/yaml.v3 to indirect require group.
go build was ok as long as go.sum has an entry for v2.
module w
go 1.20
require gopkg.in/yaml.v2 v2.4.0
require gopkg.in/yaml.v3 v3.0.1 // indirect
replace gopkg.in/yaml.v2 => gopkg.in/yaml.v3 v3.0.0
On the other hand,
--- go.mod ---
module e
go 1.20
require (
github.com/go-logr/logr v1.2.0 // indirect
k8s.io/klog v1.0.0
)
--- main.go ---
package main
import "k8s.io/klog/v2"
func main() {
_ = klog.Info
}
--- go.sum ---
github.com/go-logr/logr v1.2.0 h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
k8s.io/klog/v2 v2.90.0 h1:VkTxIV/FjRXn1fgNNcKGM8cfmL1Z33ZjXRTVxKCoF5M=
k8s.io/klog/v2 v2.90.0/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
go build returns an error (however, not explicitly talks about this path issue)
go build
main.go:3:8: no required module provides package k8s.io/klog/v2; to add it:
go get k8s.io/klog/v2
go mod tidy update go.mod to the following without error.
module e
go 1.20
require k8s.io/klog/v2 v2.90.0
require github.com/go-logr/logr v1.2.0 // indirect
replace k8s.io/klog => k8s.io/klog/v2 v2.90.0
After that go build succeed. (I don't know why).
But go list -f '{{.Module}}' k8s.io/klog reports an error
$ go list -f '{{.Module}}' k8s.io/klog
module k8s.io/klog provides package k8s.io/klog and is replaced but not required; to add it:
go get k8s.io/klog
$ go get k8s.io/klog
go: k8s.io/klog/v2@v2.90.0 used for two different module paths (k8s.io/klog and k8s.io/klog/v2)
What version of Go are you using (
go version)?What did you do?
And run
go buildNote: the go.mod isn't tidy.
What did you expect to see?
Error related to mismatching module paths. (gopkg.in/yaml.v2 vs gopkg.in/yaml.v3)
What did you see instead?
No error.
go list sees the replacement.
go mod tidyadds gopkg.in/yaml.v3 to indirect require group.go buildwas ok as long as go.sum has an entry for v2.On the other hand,
go buildreturns an error (however, not explicitly talks about this path issue)go mod tidyupdate go.mod to the following without error.After that
go buildsucceed. (I don't know why).But
go list -f '{{.Module}}' k8s.io/klogreports an error