Trying to download golang.org/x/exp/constraints

Fairly new to using go modules. I’m working through a class and they are talking about package constraints. I found the code and the valid go.mod file

module golang.org/x/exp

go 1.23.0

require (
	github.com/google/go-cmp v0.6.0
	golang.org/x/mod v0.24.0
	golang.org/x/tools v0.33.0
)

require golang.org/x/sync v0.14.0 // indirect

And I can do go mod download for for the required packages but when I try to execute:

go get golang.org/x/exp/contstraints

which should work but I get an error:

go: golang.org/x/exp/contstraints: no matching versions for query "upgrade"

I also tried downloading different commits:

go get golang.org/x/exp/contstraints@2b6e20a6d8b6a7fa47ce7f245c422b7abb361048

but I get a variety of different errors from:

golang.org/x/exp/contstraints@v0.0.0-20250506013429-2b6e20a6d8b6: invalid version: missing golang.org/x/exp/contstraints/go.mod at revision 2b6e20a6d8b6

to

go: module golang.org/x/exp@2b6e20a6d8b6a7fa47ce7f245c422b7abb361048 found (v0.0.0-20250506013429-2b6e20a6d8b6), but does not contain package golang.org/x/exp/contstraints

I realize this is experimental code and does not have any compatibility guarantee I’m more curious if I’m doing something wrong and whether or not I should be able to do this. I’m running go 1.24.2:

dan@workstation-DBDGVD3:~/Class/002-Learning_Go-Take2/023-Generics/186-Package_constraints$ go env
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/dan/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/dan/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/home/dan/tmp/go-build3918362781=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/dan/Class/002-Learning_Go-Take2/023-Generics/186-Package_constraints/go.mod'
GOMODCACHE='/home/dan/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/dan/go'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/usr/lib/golang'
GOSUMDB='off'
GOTELEMETRY='local'

Thanks in advance,

Dan

https://cs.opensource.google/go/x/exp/+/ce4c2cf36ca66590d58a095f544974374ea9c33e:go.mod

go get golang.org/x/exp/contstraints

Assuming that you’re after golang.org/x/exp/constraints, you’ve got an extra ‘t’ in there. I think that you probably intended to do this.

go get golang.org/x/exp/constraints

Yeah it was just a mistype, but I still get

go: golang.org/x/exp/constraints: no matching versions for query "upgrade"

or when I add the tag I get:

go: golang.org/x/constraints@latest: unrecognized import path "golang.org/x/constraints": reading https://golang.org/x/constraints?go-get=1: 404 Not Found
        server response: 404 page not found

even though I’m looking right at the files.

I even tried the version approach and get the same answer

dan@workstation-DBDGVD3:~/Class/002-Learning_Go-Take2/023-Generics/186-Package_constraints$ go get golang.org/x/constraints@v0.0.0-20250506013437-ce4c2cf36ca6
go: golang.org/x/constraints@v0.0.0-20250506013437-ce4c2cf36ca6: unrecognized import path "golang.org/x/constraints": reading https://golang.org/x/constraints?go-get=1: 404 Not Found
        server response: 404 page not found

even though again I’m looking right at the files, :grinning_face_with_smiling_eyes:

Are you sure that’s not another typo? You appear to have dropped the exp part of the module path.

Adding back exp works fine for me.

$ mkdir constraints-question
$ cd constraints-question
$ go mod init constraints-question
go: creating new go.mod: module constraints-question
$ go get golang.org/x/exp/constraints@v0.0.0-20250506013437-ce4c2cf36ca6
go: added golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6
$ cat go.mod
module constraints-question

go 1.24.0

require golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
$

And without an explicit version.

$ mkdir constraints-question
$ cd constraints-question
$ go mod init constraints-question
go: creating new go.mod: module constraints-question
$ go get golang.org/x/exp/constraints
go: added golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6
$ cat go.mod
module constraints-question

go 1.24.0

require golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
$

You’ve not got any configuration that might be relevant to getting modules, such as GOPROXY, GOPRIVATE, or GONOPROXY environment variables?

That did the trick, thank you so much, @pekim ++