Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: `go mod init' from 1.21 incompatible with older versions #61851

Closed
howardjohn opened this issue Aug 8, 2023 · 1 comment
Closed

cmd/go: `go mod init' from 1.21 incompatible with older versions #61851

howardjohn opened this issue Aug 8, 2023 · 1 comment

Comments

@howardjohn
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.21.0 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

Using 1.21's go mod init:

$ cd `mktemp -d`
$ go1.21.0 mod init test
$ go1.21.0 build
no Go files in ...
$ go1.20 build
go: errors parsing go.mod:
/tmp/tmp.eoz8RDYcBC/go.mod:3: invalid go version '1.21.0': must match format 1.23

We can see the result is not compatible with older versions

If we manually set the go.mod up with the same semantics, it works fine:

$ cd `mktemp -d`
$ cat <<EOF > go.mod
module test

go 1.21
EOF
$ go1.21.0 build
no Go files in ...
$ go1.20 build
no Go files in ...

What did you expect to see?

go mod init created by 1.21 can be built by older Go versions

What did you see instead?

Somewhat obscure error

@dmitshur dmitshur added this to the Go1.22 milestone Aug 8, 2023
@bcmills
Copy link
Contributor

bcmills commented Aug 8, 2023

In general a go.mod file (or Go source file) created for a higher Go version cannot be expected to successfully build with an older go version.

Starting with Go 1.21, you can use go get [email protected] or similar to explicitly downgrade for compatibility with an older release.

(You can also use the older go mod tidy flag for that, like go mod tidy -go=1.20, which works with older Go releases back to 1.17, although go get is preferred going forward.)

@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2023
mwmahlberg added a commit to mwmahlberg/swagger-ui that referenced this issue Sep 18, 2023
michurin added a commit to michurin/warehouse that referenced this issue Oct 10, 2023
@golang golang locked and limited conversation to collaborators Aug 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants