go
module_error
ai_generated
true
包 X 不在 GOROOT 中 (/usr/local/go/src/X)
package X is not in GOROOT (/usr/local/go/src/X)
ID: go/package-is-not-in-goroot
90%修复率
85%置信度
1证据数
2024-03-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| go1.21 | active | — | — | — |
| go1.22 | active | — | — | — |
| go1.23 | active | — | — | — |
根因分析
Go 工具链找不到包,因为它不在标准库路径 (GOROOT) 中,也不属于某个模块;通常是由于缺少 go.mod 或 GOPATH 问题。
English
The Go toolchain cannot find a package because it is not installed in the standard library path (GOROOT) and not part of a module; often due to missing go.mod or GOPATH issues.
官方文档
https://go.dev/doc/code#GOPATH解决方案
-
Initialize a module: `go mod init mymodule` in the project root, then run `go mod tidy`.
-
If using GOPATH, ensure the package is under `$GOPATH/src/X` and set `GO111MODULE=off`.
无效尝试
常见但无效的做法:
-
98% 失败
GOROOT must point to the Go installation, not the project; this breaks the toolchain.
-
85% 失败
This is not standard practice and will be overwritten on Go updates; also breaks module isolation.