go build_error ai_generated true

go: example.com/[email protected]: 无效的 go 版本 '1.21':必须是 X.Y.Z 格式

go: example.com/[email protected]: invalid go version '1.21': must be X.Y.Z

ID: go/invalid-go-version-in-module

其他格式: JSON · Markdown 中文 · English
80%修复率
82%置信度
0证据数
2024-04-12首次发现

版本兼容性

版本状态引入弃用备注
1.21 active
1.22 active
1.23 active

根因分析

go.mod 中的 'go' 指令指定了一个不符合所需语义版本格式的版本字符串(例如,'1.21' 而不是 '1.21.0')。

English

The 'go' directive in go.mod specifies a version string that does not follow the required semantic versioning format (e.g., '1.21' instead of '1.21.0').

generic

解决方案

  1. 95% 成功率 Correct the go directive to use proper semantic versioning (e.g., 1.21.0)
    Edit go.mod: replace 'go 1.21' with 'go 1.21.0'
  2. 90% 成功率 Use 'go mod edit -go=1.21.0' to fix it automatically
    go mod edit -go=1.21.0

无效尝试

常见但无效的做法:

  1. Changing the go directive to a non-existent version like '1.99' 80% 失败

    Go only supports releases; non-existent versions cause the toolchain to fail to locate the proper standard library.

  2. Removing the go directive entirely 50% 失败

    Without a go directive, the module defaults to an older version, potentially causing incompatibilities with newer language features.