【问题标题】:Error when running go build . with log repo运行 go build 时出错。带有日志回购
【发布时间】:2019-10-25 08:47:13
【问题描述】:

我有一个带有 gomod 的 Go 程序,当我运行 go build . 时出现以下错误:

go:github.com/sirupsen/logrus@v1.4.2 用于两个不同的模块路径(github.com/Sirupsen/logrus 和 github.com/sirupsen/logrus)

我的 go mod 看起来像

require (

github.com/Sirupsen/logrus v1.4.2 // indirect
github.com/sirupsen/logrus v1.4.2

…

) 

我添加了以下内容,但没有帮助,知道吗?

replace (
   github.com/Sirupsen/logrus v1.4.2 => github.com/sirupsen/logrus v1.4.2
)

在我的项目代码中,我使用import 路径,仅小写github.com/sirupsen/logrus

【问题讨论】:

  • @Filmzy ,这不是重复的,因为我完全按照答案中所写的内容进行了操作,并且我添加了无法解决问题的替换条目......知道如何克服这个问题吗?
  • @Flimzy ,两个答案都没有帮助,我已经尝试过了......
  • 我不明白您是如何按照这些说明进行操作的,但问题仍然存在,但我现在无法自己测试,所以我现在将重新打开。跨度>
  • 然后 grep 您的代码及其对“github.com/Sirupsen/logrus”的所有依赖项。或者先从 go.mod 中删除它。
  • 在您的代码(直接或可能间接)的某个地方,您的一个依赖项使用了错误的导入路径。找到错误的导入路径。然后摆脱那个包或修复它。

标签: go go-modules


【解决方案1】:

尝试删除//indirect这一行,然后运行

go mod tidy # prune any extraneous requirements + other stuff
go clean # remove object files and cached files
go get -v -u all # update everything related to the dependencies
go build # finger crossed!

【讨论】:

    【解决方案2】:

    github.com/sirupsen/logrus 是 v1.4.2 中 go.mod 文件中指示的正确模块名称 - https://search.gocenter.io/github.com~2Fsirupsen~2Flogrus/info?version=v1.4.2

    因此如上所述,从您的go.mod 文件中删除github.com/Sirupsen/logrus v1.4.2 的引用并运行go mod tidy。此命令会将缺少的版本化依赖项添加到您的 go.mod 文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-10
      • 2021-02-11
      • 1970-01-01
      • 2022-06-16
      • 2019-09-12
      • 1970-01-01
      • 2015-08-23
      • 1970-01-01
      相关资源
      最近更新 更多