go module_error ai_generated true

没有必需的模块提供包 github.com/foo/bar;要添加它: go get github.com/foo/bar

no required module provides package github.com/foo/bar; to add it: go get github.com/foo/bar

ID: go/cannot-find-module-providing-package

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

版本兼容性

版本状态引入弃用备注
1.16+ active — — —
1.21+ active — — —

根因分析

源码中使用了该导入,但 go.mod 中没有提供该模块的 require 条目,且 -mod=readonly 阻止自动添加。

English

The import is used in source but go.mod has no require entry for the providing module, and -mod=readonly prevents auto-adding.

generic

解决方案

  1. 95% 成功率
    go get github.com/foo/bar@latest
    go mod tidy
  2. 90% 成功率
    go build -mod=mod ./...

无效尝试

常见但无效的做法:

  1. 70% 失败

    wrong version causes 'unknown revision' or checksum errors

  2. 90% 失败

    build fails with 'vendor directory does not exist'

  3. 60% 失败

    loses all existing dependency pins and may break transitive deps