go: x/tools/gopls: the code in the workspace failed to compile

What version of Go are you using (go version)?

go version go1.15 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\www\AppData\Local\go-build
set GOENV=C:\Users\www\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=E:\GoProject\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\GoProject\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=E:\Go
set GOSUMDB=sum.golang.google.cn
set GOTMPDIR=
set GOTOOLDIR=E:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\www\AppData\Local\Temp\go-build025204942=/tmp/go-build -gno-record-gcc-switches

What did you do?

when I use vscode open my gopath folder, it shows that The code in the workspace failed to compile (see the error message below) and go [-e -json -compiled=true -test=true -export=false -deps=true -find=false – ./]: exit status 1: go: cannot find main module; see ‘go help modules’: packages.Load error.

What did you expect to see?

What did you see instead?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

I have solved this question

i have met the same problems, version 0.16.1. i have set go.mod file correctly(GOMOD is ok). But the promotion is always occured when i open modify etc…

I have solved this problem in vscode.In setting json,I add “go.buildOnSave”: “workspace”,

Looks like GO111MODULE=on but there is no go.mod (i.e. GOMOD=NUL). Please see https://github.com/golang/vscode-go/issues/275#issue-648468015 and make sure to open vscode from the folder with go.mod file.

@PICKQUE: Please make sure to open your workspace to your module root (the directory containing the go.mod file). This is currently a requirement of gopls, but we’re working on changing that in future versions. If that doesn’t resolve the problem, please file a new issue.

Looks like GO111MODULE=on but there is no go.mod (i.e. GOMOD=NUL). Please see golang/vscode-go#275 (comment) and make sure to open vscode from the folder with go.mod file.

Wonderful! Solved my problem!