【问题标题】:Error scanning github.com/golang/protobuf/proto/testdata: cannot find package "."扫描 github.com/golang/protobuf/proto/testdata 时出错:找不到包“。”
【发布时间】:2019-03-24 23:24:29
【问题描述】:

在我的项目上运行 glide install 时,我收到以下错误:

[ERROR] Error scanning github.com/golang/protobuf/proto/testdata: cannot find package "." in:
    /Users/bevernie/.glide/cache/src/https-github.com-golang-protobuf/proto/testdata
[ERROR] Failed to retrieve a list of dependencies: Error resolving imports

查看protobuf的源码时,其实可以看到没有这个包。但是我不直接使用 protobuf,所以错误一定来自我使用的依赖项之一。

在我的项目上运行glide tree 时,github.com/golang/protobuf/proto/testdata 只有一个实例:

|-- github.com/golang/protobuf/proto   (/Users/bevernie/Programmation/work/src/github.com/golang/protobuf/proto)
|   |-- github.com/golang/protobuf/proto/test_proto   (/Users/bevernie/Programmation/work/src/github.com/golang/protobuf/proto/test_proto)
|   |   |-- (Recursion) github.com/golang/protobuf/proto   (/Users/bevernie/Programmation/work/src/github.com/golang/protobuf/proto)
|   |-- github.com/golang/protobuf/ptypes/any   (/Users/bevernie/Programmation/work/src/github.com/golang/protobuf/ptypes/any)
|   |   |-- (Recursion) github.com/golang/protobuf/proto   (/Users/bevernie/Programmation/work/src/github.com/golang/protobuf/proto)
    github.com/golang/protobuf/proto/testdata   (glide get github.com/golang/protobuf/proto/testdata)
|-- github.com/golang/protobuf/ptypes/any   (/Users/bevernie/Programmation/work/src/github.com/golang/protobuf/ptypes/any)
|   |-- github.com/golang/protobuf/proto   (/Users/bevernie/Programmation/work/src/github.com/golang/protobuf/proto)
|   |   |-- github.com/golang/protobuf/proto/test_proto   (/Users/bevernie/Programmation/work/src/github.com/golang/protobuf/proto/test_proto)
|   |   |   |-- (Recursion) github.com/golang/protobuf/proto   (/Users/bevernie/Programmation/work/src/github.com/golang/protobuf/proto)
|   |   |-- (Recursion) github.com/golang/protobuf/ptypes/any   (/Users/bevernie/Programmation/work/src/github.com/golang/protobuf/ptypes/any)

这并不能真正帮助我查明问题的根源。

您对如何解决这些问题有任何建议吗?

直到一两周前,我的项目编译还不错(我使用 Docker 部署到生产环境中,所以每次都运行 glide install 并且在此之前从未失败过,而且我最近没有添加任何新的依赖项) .

【问题讨论】:

    标签: go protocol-buffers glide-golang


    【解决方案1】:

    在你自己的PR (995)之前,有glide issue 968

    这似乎是由存储库的结构变化引起的,即子包被移动或完全删除。

    Elliot Wright (seeruk)提出的解决方法:

    如果已更新的包在您自己的控制之下,那么我发现使用一些较新的 Go 功能(如类型别名)来减轻重构带来的痛苦会更容易。
    因此,与其只是移动一个包,不如移动它,然后为旧包中的新位置创建别名,这样您的旧代码仍然可以工作。
    然后,逐渐将事情转移过来。基本上只是将事物标记为已弃用,但确保它们仍然可以使用一段时间,直到您移植新代码为止。

    如果包在您的控制范围内,那么您始终可以手动将所需的版本克隆到您的供应商文件夹并在您的代码中进行更新。
    完成后,Glide 应该会让您再次更新。
    如果它更复杂,有时在您完成更新包之前恢复使用go get 会更容易,并依赖于您的$GOPATH 内容。

    这远非理想,但至少有一些方法可以解决它。
    同时,我也在 dep 上对此提出了问题。
    我认为他们正在研究一种禁用这种检查的方法,如果您只是希望该工具信任您作为开发人员。

    因此,您可以使用godep,甚至是最前沿的vgo 来检查您是否有同样的问题。

    【讨论】:

    • 感谢您的回答,我已经为这个项目切换到 dep 并且没有问题了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 2022-04-04
    • 2020-08-17
    • 2015-06-02
    相关资源
    最近更新 更多