简体   繁体   English

将/ vendor转换为Go模块,找不到提供包错误的模块

[英]Converting /vendor to Go Modules, cannot find module providing package error

Converting an existing project with a /vendor directory to use Go Modules (go version 1.12). 将带有/ vendor目录的现有项目转换为使用Go Modules(1.12版)。 I do go mod init to generate the go.mod file. 我使用go mod init来生成go.mod文件。 Then I do go get -u ./... to populate the go.mod file. 然后我执行go get -u ./... -u。/ go get -u ./...来填充go.mod文件。 During this time, it tries to locate a package on github that no longer exists. 在此期间,它将尝试在不再存在的github上找到一个包。 It is vendored in my /vendor directory. 它在我的/ vendor目录中提供。

Until I can upgrade my code to use a different package, how can I continue the conversion to using modules? 在可以升级代码以使用其他软件包之前,如何继续转换为使用模块? That is, I want to keep some things vendored (I also have some modified code under /vendor), while other things are handled by go modules. 也就是说,我想保留一些东西(在/ vendor下也有一些修改的代码),而其他东西则由go模块处理。

You can't mix the vendor directory behavior and modules, each method of dependency resolution precludes the other. 您不能混合使用vendor目录的行为和模块,每种依赖关系解决方法都不能使用其他方法。 You can re-publish the missing package yourself somewhere that go mod can locate it, or you can redirect it directly to the existing vendored source in your module. 您可以在go mod可以找到它的位置自己重新发布缺少的包,也可以将其直接重定向到模块中现有的供应商源。

To redirect the source of a module, use the replace directive in the go.mod file 要重定向模块的源代码,请在go.mod文件中使用replace指令

replace missing/package v0.0.1 => ./vendor/missing/package

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM