go
module_error
ai_generated
true
包 example.com/foo 不在 GOROOT 中 (/usr/local/go/src/example.com/foo)
package example.com/foo is not in GOROOT (/usr/local/go/src/example.com/foo)
ID: go/package-not-found-in-goroot
80%修复率
87%置信度
0证据数
2025-04-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.16 | active | — | — | — |
| 1.17 | active | — | — | — |
根因分析
导入路径被错误解析为GOROOT下的标准库,而不是模块依赖。
English
Import path is incorrectly resolved to GOROOT's standard library instead of a module dependency.
解决方案
-
80% 成功率 确保在模块目录内运行
cd /path/to/module && go build
-
90% 成功率 设置GO111MODULE=on
export GO111MODULE=on go build
无效尝试
常见但无效的做法:
-
复制包到GOROOT目录
90% 失败
GOROOT不应被修改,且这不是正确做法。
-
设置GO111MODULE=off
70% 失败
禁用模块模式会导致其他依赖问题。