Module lookup disabled by GOPROXY=off golangci 由于GOPROXY=off golangci,模块查找被禁用。

huangapple go评论81阅读模式
英文:

Module lookup disabled by GOPROXY=off golangci

问题

我有一个供应商文件夹和一个 CI/CD 任务的 Linter。在将文件夹推送到 GitLab 之前,我执行了以下操作:

go mod tidy
go mod vendor

我的 Makefile 中的 Linter 任务如下:

@GO111MODULE=on GOFLAGS=-mod=vendor GOPROXY=off $(GOLINT) run ./... -v --max-same-issues 0

在本地启动 Linter 时,我没有任何问题。但是在 CI/CD 过程中,我遇到了一个错误:

> 运行错误:上下文加载失败:加载包失败:使用 go/packages 加载失败:错误:退出状态 1:stderr:go:
> github.com/jmoiron/sqlx@v1.3.1: 由于 GOPROXY=off,模块查找被禁用

所以我不明白为什么会出现这个错误

更新
我决定删除 vendor、go.mod 和 go.sum。然后我创建了新的 go.mod 并执行了以下操作:

go mod vendor

之后,我遇到了同样的错误,但是是关于另一个包的错误:

> level=error msg="运行错误:上下文加载失败:加载包失败:使用 go/packages 加载失败:错误:退出状态 1:stderr:
> go: github.com/fsnotify/fsnotify@v1.5.1: 由于 GOPROXY=off,模块查找被禁用

英文:

I have a vendor folder and CI/CD task Linter. Before push the folder to gitlab I did

go mod tidy
go mod vendor

My Linter task in Makefile looks like

@GO111MODULE=on GOFLAGS=-mod=vendor GOPROXY=off $(GOLINT) run ./... -v --max-same-issues 0

and I have no any problems when I start linting locally. But during CI/CD I got an error

> Running error: context loading failed: failed to load packages: failed
> to load with go/packages: err: exit status 1: stderr: go:
> github.com/jmoiron/sqlx@v1.3.1: module lookup disabled by GOPROXY=off

So i can't understand why I got this error

Update
I decided to remove the vendor, go.mod and go.sum. Then I created new go.mod and did

go mod vendor

After that I got the same error but with another package

> level=error msg="Running error: context loading failed: failed to load
> packages: failed to load with go/packages: err: exit status 1: stderr:
> go: github.com/fsnotify/fsnotify@v1.5.1: module lookup disabled by
> GOPROXY=off

答案1

得分: 0

问题出在golangci的modules-download-mode设置上。

解决方法是将该变量设置为vendor模式:

modules-download-mode: vendor
英文:

The problem was in the settings of golangci modules-download-mode

this solution is set this variable to vendor mode:

modules-download-mode: vendor

huangapple
  • 本文由 发表于 2022年3月1日 18:51:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/71307320.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定