module declares its path as: xxx

go version go1.15.11 darwin/amd64

在私有仓库创建了一个xxx的项目

gitlab.aaa.cn/x/xxx

然后创建go mod xxx

在另一个项目中使用这个包

先配置go env -w GOPRIVATE=gitlab.aaa.cn

然后import 这个包, go gitlab.aaa.cn/x/xxx

然后就报错

module declares its path as: xxx
but was required as: gitlab.aaa.cn/x/xxx

这个时候需要删除xxx包的go.mod ,然后重新初始化为go mod  gitlab.aaa.cn/x/xxx 而不是之前的go mod  xxx

原文地址:https://www.cnblogs.com/leescre/p/14864581.html