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)
I have solved this question
I have solved this problem in vscode.In setting json,I add “go.buildOnSave”: “workspace”,
Looks like
GO111MODULE=onbut there is nogo.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 withgo.modfile.@PICKQUE: Please make sure to open your workspace to your module root (the directory containing the
go.modfile). This is currently a requirement ofgopls, but we’re working on changing that in future versions. If that doesn’t resolve the problem, please file a new issue.Wonderful! Solved my problem!