英文:
What does "inconsistent vendoring" mean in Go?
问题
我正在遇到这个不一致的供应商错误,而我是一个完全不懂Go的新手。有人可以解释一下go.mod如何与vendor/modules.txt交互吗?我在这个问题中找到了一些有用的信息,现在我想知道我是否应该有一个vendor目录。运行go mod vendor
会创建它吗?我继承了这个项目,它已经在git中有了vendor目录。
这是我go.mod文件的相关部分:
module mymodule
go 1.17
require (
gopkg.in/redis.v5 v5.2.9
)
然后是相关的错误信息:
go: inconsistent vendoring
gopkg.in/redis.v5@v5.2.9: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
在vendor/modules.txt中,我有:
#gopkg.in/redis.v5 v5.2.9
gopkg.in/redis.v5
gopkg.in/redis.v5/internal
gopkg.in/redis.v5/internal/consistenthash
gopkg.in/redis.v5/internal/hashtag
gopkg.in/redis.v5/internal/pool
gopkg.in/redis.v5/internal/proto
值得一提的是,我对go.mod文件中的每个依赖项都遇到了这个错误,我只是包括了关于redis的一个。
英文:
I'm getting this inconsistent vendoring error and I'm a total Go newbie. Can anyone explain to me how go.mod interacts with vendor/modules.txt? I found this question helpful, and now I'm wondering if I should even have a vendor directory. Would that be created by running go mod vendor
? I inherited this project and it already has the vendor directory in git.
Here's the relevant part of my go.mod file -
module mymodule
go 1.17
require (
gopkg.in/redis.v5 v5.2.9
)
And then the related error message:
go: inconsistent vendoring
gopkg.in/redis.v5@v5.2.9: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
In vendor/modules.txt I have:
#gopkg.in/redis.v5 v5.2.9
gopkg.in/redis.v5
gopkg.in/redis.v5/internal
gopkg.in/redis.v5/internal/consistenthash
gopkg.in/redis.v5/internal/hashtag
gopkg.in/redis.v5/internal/pool
gopkg.in/redis.v5/internal/proto
For what it's worth I'm getting this error for every dependency in my go.mod file, I just included the one about redis.
答案1
得分: 7
go.mod
和vendor/modules.txt
(如果存在)必须保持同步。
每当go.mod
发生更改并且存在vendor
目录时,需要运行go mod vendor
来更新vendor
目录的内容。
所有直接依赖项(在go.mod
中未标记为// implicit
)从Go 1.14开始都是“explicit”,并在vendor/modules.txt
中相应地标记。
在运行go mod vendor
之后,请注意在包引用之后添加了新行## explicit
:
#gopkg.in/redis.v5 v5.2.9
## explicit
. . .
英文:
go.mod
and vendor/modules.txt
(if present) must be in sync.
Whenever go.mod
changes and there is a vendor
directory, go mod vendor
needs to be run to update the contents of the vendor
directory.
All direct dependencies (not marked // implicit
in go.mod
) are "explicit" and marked accordingly in vendor/modules.txt
starting from Go 1.14.
After running go mod vendor
notice the new line ## explicit
added after the package reference:
#gopkg.in/redis.v5 v5.2.9
## explicit
. . .
答案2
得分: 4
只是为了补充@rustyx的答案,为了修复这个错误,我删除了vendor
文件夹,然后再次运行了go mod vendor
,错误就消失了。
英文:
Just to add to @rustyx's answer, in order to fix this error, I deleted the vendor
folder and then I ran again go mod vendor
, and the error disappeared.
答案3
得分: 0
对我来说,更新版本解决了这个问题。我之前使用的是go1.16,我更新到了go1.18.2。在更新之前,我尝试了go mod vendor,并且更新modules.txt也没有起作用,然后我开始通过运行go build -mod=mod来忽略vendor目录来构建应用程序,或者通过运行go run -mod=mod main.go来运行main.go文件。
英文:
For me updating the version solved the issue. I was running go1.16 and I updated to go1.18.2. Before the update I tried go mod vendor and also updating the modules.txt didn't work then, I started ignoring the vendor directory by running
go build -mod=mod to build the application or go run -mod=mod main.go to run the main.go file
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论