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?
A simple command in the terminal helped me:
brew upgrade go
GoLang has been updated, I have restarted the project, and everything is working
我删除了 go 并再次安装,然后问题就解决了。
我通过使用https://go.dev/doc/manage-install来解决这个问题,更改我当前的 golang 版本(1.16),并设置项目需要的版本,然后设置我的 GOROOT 和 PATH,使用新的版本,然后运行go mod tidy
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.
I had the same error in Goland and solved it by restarting the IDE. May also work in Visual Studio.
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
then choose the right one, for me go1.19.1.
VScode ask you to reload Windows
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.