【问题标题】:Module declared as X but was required as Y模块声明为 X 但要求为 Y
【发布时间】:2020-02-24 05:04:09
【问题描述】:

我正在尝试在我的模块中使用 grafana/grafana/pkg/tsdb 包。我不认为这个问题是 grafana 特有的,但它就是这样:

$ go get -u github.com/grafana/grafana/pkg/tsdb
go: finding github.com/inconshreveable/log15 latest
go: finding github.com/go-macaron/session latest
go: finding golang.org/x/oauth2 latest
go: finding github.com/teris-io/shortid latest
go: github.com/grafana/grafana/pkg/tsdb imports
        github.com/go-xorm/core: github.com/go-xorm/core@v0.6.3: parsing go.mod:
        module declares its path as: xorm.io/core
                but was required as: github.com/go-xorm/core

它说包tsdb 将xorm 导入为github.com/go-xorm/core,但模块将自己声明为xorm.io/core

查看 Grafana 的 go.mod 文件,它正在使用 github.com/go-xorm/core 并转到 github.com/go-xorm/core,它说该项目现在已存档...并且它的 go.mod 文件确实将自己声明为 xorm.io/core...

以及如何解决此问题的建议?

【问题讨论】:

    标签: go go-modules go-xorm


    【解决方案1】:

    编辑:我也很幸运只是使用了一个稍旧的版本:

    go get github.com/grafana/grafana/pkg/tsdb@6.6.1
    

    我尝试了替换,它有时可以工作:

    module foo
    
    replace github.com/go-xorm/core => xorm.io/core v0.6.2
    
    go 1.13
    
    require (
    ...
    

    但我收到类型错误。

    幸运的是,似乎有一个 PR 可以解决这个问题:https://github.com/grafana/grafana/pull/22376

    【讨论】:

    • 感谢您的回复。对于 xorm/core 库中的 grafana b/c grafana 供应商来说,这不是问题,并且它供应的版本具有包名称 github.com/go-xorm/core。看起来 xorm 将他们的存储库迁移到了 gitea...
    • 您的解决方法(安装 6.6.1)确实有效。谢谢。我已经接受了答案。
    猜你喜欢
    • 2016-12-06
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多