首页 > 文章列表 > 使用 go mod 遇到 \"package xxx is not in GOROOT\" 错误怎么办?

使用 go mod 遇到 \"package xxx is not in GOROOT\" 错误怎么办?

318 2025-01-05

使用 go mod 遇到

使用 go mod 遇到 "package xxx is not in GOROOT" 错误

刚接触 Go 的开发者有时会在使用 go mod 时遇到 "package xxx is not in GOROOT" 错误。这通常是由以下原因引起的:

  • GO111MODULE 未正确设置:确保在环境变量中将 GO111MODULE 设置为 "on",这会指示 Go 模块处于启用状态。

以下是一个解决示例:

  1. 检查你的 go.mod 文件是否存在,如果没有,请创建一个。
  2. 确保你的包名为小写字母,与目录名匹配。
  3. 确保你的 GO111MODULE 环境变量已设置为 "on"。
  4. 尝试运行 go mod tidy 命令。
来源:1730289264