# go: 找不到主模块；请参阅 'go help modules'
	当前目录在任何模块之外
	在 /home/user/project 或任何父目录中未找到 go.mod 文件

- **ID:** `go/missing-go-mod-file`
- **领域:** go
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

当前工作目录不包含 go.mod 文件，且任何父目录都没有，因此 Go 无法确定模块上下文。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.11 | active | — | — |
| 1.12 | active | — | — |
| 1.13 | active | — | — |
| 1.14 | active | — | — |
| 1.15 | active | — | — |
| 1.16 | active | — | — |
| 1.17 | active | — | — |
| 1.18 | active | — | — |
| 1.19 | active | — | — |
| 1.20 | active | — | — |
| 1.21 | active | — | — |
| 1.22 | active | — | — |
| 1.23 | active | — | — |

## 解决方案

1. **Initialize the module with 'go mod init'** (95% 成功率)
   ```
   go mod init example.com/project
   ```
2. **Navigate to a directory that contains a go.mod file** (90% 成功率)
   ```
   cd /path/to/valid/module && go build
   ```

## 无效尝试

- **Creating a go.mod file with arbitrary content** — The module path must be correct; arbitrary content may cause import resolution failures. (70% 失败率)
- **Setting GO111MODULE=off to use GOPATH mode** — If the project is not in GOPATH, it still fails; also disables modern module features. (60% 失败率)
