当我运行go mod tidy时,有几个包显示错误

> go mod tidy

github.com/myrepo/myproj imports
    go.k6.io/k6 imports
    go.k6.io/k6/cmd imports
    github.com/fatih/color loaded from github.com/fatih/color@v1.12.0,
    but go 1.16 would select v1.13.0

To upgrade to the versions selected by go 1.16:
    go mod tidy -go=1.16 && go mod tidy -go=1.17
If reproducibility with go 1.16 is not needed:
    go mod tidy -compat=1.17
For other options, see:
    https://golang.org/doc/modules/pruning

我已经安装了go 1.17.9.错误的含义是什么?为什么会触发错误?

推荐答案

该错误与Go 1.17中引入的module graph pruning有关.

对于Go 1.16,用于最小版本 Select 的模块图用于包括完整的模块图,而对于Go 1.17,该图仅包括最多可传递的依赖项(除了一些例外,请参见上面的链接).

现在要了解是什么触发了错误,您可能需要查看Go 1.17 release notes:

默认情况下,go mod tidy验证与主模块相关的依赖项的所选版本是否与之前的Go版本相同(Go 1.16用于指定Go 1.17的模块)[……]

因此,当您运行go mod tidy时,它会报告Go 1.16"将 Select "一个可传递依赖项(github.com/fatih/color)的版本,该版本与Go 1.17的修剪图所 Select 的版本不同.

这与构建再现性有关,因为go.sum包含go.mod and the previous one中指定的当前Go版本的校验和.在Go 1.17和Go 1.16中,模块图可以有效更改,go.sum将不一致.

错误消息建议进行两次修复.

  1. go mod tidy -go=1.16 && go mod tidy -go=1.17-这将 Select 依赖项版本为Go 1.16,然后 Select Go 1.17

  2. go mod tidy -compat=1.17-这只是删除了Go 1.16校验和(因此提示"不需要Go 1.16的再现性").

在升级到Go 1.18后,错误应该不会再出现,因为这样模块图将与Go 1.17中的加载相同.

Go相关问答推荐

Golang regexpp:获取带有右括号的单词

在字符串与字符串子切片上使用len进行位转移产生意外输出

Term~T中的类型不能是类型参数,但可以是引用类型参数的切片

编辑时保留YAML文件中的单引号

创建使用逗号而不是加号分隔OU的CSR

从使用Golang otelmux检测的Otel跟踪中获取trace_id

Golang telegram 机器人

Golang和Gin web框架在router.Run()之后执行代码

GoLang:net.LookupHost 返回重复的 ips

缺少签名帮助文档

闭包所处的环境范围是什么?

为什么不同的 Wireguard 私钥会产生相同的公钥?

获取不带类型参数的泛型 struct 的类型名称

如何将文件上传到 Google Drive,并与使用服务帐户和 Golang 的任何人共享

在 go 中将运行命令的标准输出发送到其标准输入

如何在测试中使用自定义标志(使用`testify/suite`)

Golang 数据库/sql 与 SetMaxOpenConns 挂起

具有相同提前返回语句的函数的不同基准测试结果

从 Go struct 中提取标签作为 reflect.Value

map和struct golang的合并