22

I am getting error on Visual Studio Code:

Command 'gopls.tidy' failed: Error: err: exit status 1: stderr: go mod tidy: go.mod file indicates go 1.17, but maximum supported version is 1.16 .

I can't fix it with go mod tidy and go mod init. How can I solve this?

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
srls01
  • 425
  • 2
  • 4
  • 12
  • 3
    I believe this is because you are running Go v1.16 locally, but your go.mod file requests that you have at least v1.17. So update your go version or change the go.mod file. But be aware that v1.17 code may not work for your v1.16 install, hence this error – Dylan Reimerink Apr 15 '22 at 08:40
  • 1
    can I change go.mod version? if I can, how? – srls01 Apr 15 '22 at 10:39
  • 1
    @srls01 check this https://stackoverflow.com/questions/60675415/how-to-upgrade-the-go-version-in-a-go-mod – blackgreen Apr 15 '22 at 10:56

9 Answers9

25

A simple command in the terminal helped me:

brew upgrade go

GoLang has been updated, I have restarted the project, and everything is working

Sergei
  • 251
  • 2
  • 3
20

If you are using IntelliJ or GoLand built-in terminal, change GOROOT on this page:

screenshot

then restart the IDE.

Kokizzu
  • 24,974
  • 37
  • 137
  • 233
3

This issue occurs when your GOROOT and/or you GOTOOLDIR and/or your GOVERSION environment indicates a lower version than the one defined in you .mod file.

To check, run go env in the terminal within vscode:

# in my own case:
go env
...
GOROOT="/home/me/sdk/go1.18.1"
...
GOTOOLDIR="/home/me/sdk/go1.18.1/pkg/tool/linux_amd64"
...
GOVERSION="go1.18.1"
...

where my .mod indicates go 1.19, so go mod tidy prints the error.

To change your current go version in vscode: CRTL+P > and enter go:choose go environment

or click on the go version on the status bar enter image description here

then choose the right one, for me go1.19.1.

VScode ask you to reload Windows

enter image description here

but even if you click to reload, the go environement variables are not updated! The only way I found is to close VSCode and to REOpen it, that'it.

By doing so, VSCode setup the go environment variables to the one you've choosen to make your development.

Hope this can help

miky
  • 97
  • 7
2

I had the same error in Goland and solved it by restarting the IDE. May also work in Visual Studio.

KawaLo
  • 1,783
  • 3
  • 16
  • 34
1

I solved thisby using https://go.dev/doc/manage-install, to change my current version of golang (1.16), and set the version that the project needs, then set my GOROOT and PATH of go, with the new version and then run go mod tidy

0

I deleted go and installed again then problem is solved.

srls01
  • 425
  • 2
  • 4
  • 12
0

This is the error i got:

go mod tidy: go.mod file indicates go 1.18, but maximum supported version is 1.17

My GOROOT was 1.18 but somehow my it seems changed to 1.17 version. I think Goland misguided and in your case it could be VSCode.

Anyway, i changed my GOROOT sdk version to 1.18 and problem solved.

Alteran
  • 91
  • 8
0

I had this issue on GoLand, hopefully it helps someone in the same situation:

You can check and update the version it's using on Preferences -> Go -> GOROOT enter image description here

And if you are using a terminal, remember to close it and open it again.

-1

you can also change the go version to 1.18 or whichever it complains about, then run go mod tidy and then change it back to what the go version was before