# 包 X 不在 GOROOT 中 (/usr/local/go/src/X)

- **ID:** `go/package-is-not-in-goroot`
- **领域:** go
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

Go 工具链找不到包，因为它不在标准库路径 (GOROOT) 中，也不属于某个模块；通常是由于缺少 go.mod 或 GOPATH 问题。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| go1.21 | active | — | — |
| go1.22 | active | — | — |
| go1.23 | active | — | — |

## 解决方案

1. ```
   Initialize a module: `go mod init mymodule` in the project root, then run `go mod tidy`.
   ```
2. ```
   If using GOPATH, ensure the package is under `$GOPATH/src/X` and set `GO111MODULE=off`.
   ```

## 无效尝试

- **** — GOROOT must point to the Go installation, not the project; this breaks the toolchain. (98% 失败率)
- **** — This is not standard practice and will be overwritten on Go updates; also breaks module isolation. (85% 失败率)
