how to solve "stderr: go mod tidy: go.mod file indicates go 1.17, but maximum supported version is 1.16 ." error?

huangapple go评论90阅读模式
英文:

how to solve "stderr: go mod tidy: go.mod file indicates go 1.17, but maximum supported version is 1.16 ." error?

问题

我在 Visual Studio Code 上遇到了错误:

> 命令 'gopls.tidy' 失败:错误:err: 退出状态 1:stderr:go mod tidy: go.mod 文件指示 go 1.17,但最大支持版本是 1.16。

我无法通过 go mod tidygo mod init 来解决它。我该如何解决这个问题?

英文:

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?

答案1

得分: 25

一个简单的终端命令帮助了我:

brew upgrade go

Go语言已经更新,我已经重新启动了项目,一切都正常工作。

英文:

A simple command in the terminal helped me:

brew upgrade go

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

答案2

得分: 20

如果你正在使用IntelliJ或GoLand内置终端,请在此页面上更改GOROOT

how to solve "stderr: go mod tidy: go.mod file indicates go 1.17, but maximum supported version is 1.16 ." error?

然后重新启动IDE。

英文:

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

how to solve "stderr: go mod tidy: go.mod file indicates go 1.17, but maximum supported version is 1.16 ." error?

then restart the IDE.

答案3

得分: 3

这个问题发生在你的 GOROOT 和/或 GOTOOLDIR 和/或 GOVERSION 环境变量指示的版本低于你的 .mod 文件中定义的版本时。

要检查,请在 vscode 终端中运行 go env 命令:

# 在我的情况下:
go env
...
GOROOT="/home/me/sdk/go1.18.1"
...
GOTOOLDIR="/home/me/sdk/go1.18.1/pkg/tool/linux_amd64"
...
GOVERSION="go1.18.1"
...

我的 .mod 文件指示的是 go 1.19,所以 go mod tidy 命令会输出错误信息。

要在 vscode 中更改当前的 go 版本:
按下 CRTL+P,然后输入 go:choose go environment
或者点击状态栏上的 go 版本图标,
然后选择正确的版本,对我来说是 go1.19.1。

VSCode 会要求你重新加载窗口。

但是,即使你点击重新加载,go 环境变量也不会更新!我找到的唯一方法是关闭 VSCode 并重新打开它。

这样做,VSCode 会设置 go 环境变量为你选择的版本,以便进行开发。

希望这能帮到你。

英文:

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
how to solve "stderr: go mod tidy: go.mod file indicates go 1.17, but maximum supported version is 1.16 ." error?

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

VScode ask you to reload Windows

how to solve "stderr: go mod tidy: go.mod file indicates go 1.17, but maximum supported version is 1.16 ." error?

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

答案4

得分: 2

我在Goland中遇到了相同的错误,并通过重新启动IDE解决了它。在Visual Studio中也可能起作用。

英文:

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

答案5

得分: 1

我通过使用https://go.dev/doc/manage-install来解决这个问题,来更改我的当前版本的golang(1.16),并设置项目所需的版本,然后设置我的GOROOT和go的PATH,使用新版本运行go mod tidy

英文:

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

答案6

得分: 0

我删除了go并重新安装,问题得到解决。

英文:

I deleted go and installed again then problem is solved.

答案7

得分: 0

这是我得到的错误:

go mod tidy: go.mod文件指示使用go 1.18,但最大支持版本是1.17

我的GOROOT是1.18,但不知何故它似乎变成了1.17版本。我认为是Goland引导错误了,在你的情况下可能是VSCode。

无论如何,我将我的GOROOT SDK版本更改为1.18,问题解决了。

英文:

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.

答案8

得分: -1

你可以将Go版本更改为1.18或者它所抱怨的任何版本,然后运行go mod tidy,然后再将它改回之前的Go版本。

英文:

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

huangapple
  • 本文由 发表于 2022年4月15日 16:24:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/71881727.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定