20

When trying to lookup some modules, I am having an issue from VS Code where the error pictured below indicates that my GOPROXY is set to off, but when I run go env, I see that GOPROXY is actually set:GOPROXY="https://repo1.mycompany.com/artifactory/api/go/golang-virtual,https://proxy.golang.org,direct"

I have tried setting GONOPROXY='', as this comment suggests, but after running export GONOPROXY= or export GONOPROXY="", and checking go env in a new terminal tab, GONOPROXY is still set to: GONOPROXY="*.mycompany.com"

Running go mod tidy as VS Code suggests, results in the same error message.

Is it possible that my go env values are being set somewhere that I don't know about, maybe a different version of Go's env vars? Thanks in advance, any help is greatly appreciated.

VS Code's error screenshot: enter image description here

Andrew Smith
  • 483
  • 1
  • 3
  • 16
  • 6
    Did you restart vscode from the same environment where you exported the variables? – JimB Feb 07 '22 at 17:58
  • 6
    Thanks. Reloading the vs code window alone was enough to fix my issue. – Andrew Smith Feb 07 '22 at 20:29
  • 1
    Can you tell me a bit more on what you were trying to do? ("lookup some modules") The error message is very confusing (the `GOPROXY=off` in the message was set by gopls internally to prevent unwanted network access or module update) and needs to improve. – Hana Feb 11 '22 at 14:08
  • I was trying to "go run" my program, which I have been able to do in the past, but VS Code was throwing this error when I opened the project. I agree that the error message is confusing and needs to improve. Thanks for explaining that this was set by gopls. For some reason, reloading the screen in VS Code fixed the issue. – Andrew Smith Feb 14 '22 at 15:06

2 Answers2

31

Simply Ctrl + Shift + P > Developer: Reload window

enter image description here

ABDULLOKH MUKHAMMADJONOV
  • 4,249
  • 3
  • 22
  • 40
1

The latest docs have updated the GOPROXY flag proxy.golang.org, which states:

To opt-out of this module mirror, you can turn it off by setting GOPROXY=direct

So to bypass the proxy and fetch directly from the URLs in go.mod:

export GOPROXY=direct

go clean --modcache
go get -u
go build
Josh Hibschman
  • 3,148
  • 1
  • 25
  • 27