go build_error ai_generated true

go: 设置了 -mod=vendor 但 vendor 目录缺失或不完整

go: -mod=vendor is set but vendor directory is missing or incomplete

ID: go/vendor-directory-missing

其他格式: JSON · Markdown 中文 · English
80%修复率
90%置信度
0证据数
2024-09-12首次发现

版本兼容性

版本状态引入弃用备注
1.21 active — — —
1.22 active — — —
1.23 active — — —

根因分析

使用 vendor 模式时,vendor 目录不存在或缺少必需的依赖项。

English

The vendor directory does not exist or lacks required dependencies when using vendor mode.

generic

解决方案

  1. 95% 成功率 Run 'go mod vendor' to populate the vendor directory.
    Execute 'go mod vendor' in the module root to copy all dependencies.
  2. 90% 成功率 Use -mod=mod flag to bypass vendor mode.
    Build with 'go build -mod=mod' to use module cache instead of vendor.

无效尝试

常见但无效的做法:

  1. Creating an empty vendor directory manually. 100% 失败

    Go expects the vendor directory to contain all dependencies; empty directory causes build failures.

  2. Setting GOFLAGS=-mod=mod to ignore vendor. 30% 失败

    This works but doesn't fix the vendor issue; it's a workaround, not a fix.