Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kittyhappy opened this issue Aug 14, 2020 · 11 comments
Closed

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

kittyhappy opened this issue Aug 14, 2020 · 11 comments

Comments

@kittyhappy
Copy link

@kittyhappy kittyhappy commented Aug 14, 2020

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?

@dmitshur dmitshur added this to the Unreleased milestone Aug 17, 2020
@dmitshur dmitshur changed the title The code in the workspace failed to compile x/tools/gopls: the code in the workspace failed to compile Aug 17, 2020
@dmitshur
Copy link
Member

@dmitshur dmitshur commented Aug 17, 2020

Are you using the vscode-go extension? If so, what version is it?

Have you tried the troubleshooting steps described in https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md?

/cc @stamblerre

@hyangah
Copy link
Contributor

@hyangah hyangah commented Aug 17, 2020

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.

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v.0.5.0 Aug 25, 2020
@mrlay
Copy link

@mrlay mrlay commented Aug 26, 2020

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...

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Aug 26, 2020

@mrlay: Please provide your gopls logs. Information on how to capture them can be found here.

@kittyhappy
Copy link
Author

@kittyhappy kittyhappy commented Aug 27, 2020

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",

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Aug 27, 2020

Glad you were able to solve it. I'm going to close this issue. @mrlay, please file a new issue to continue this discussion.

@stamblerre stamblerre closed this Aug 27, 2020
@PICKQUE
Copy link

@PICKQUE PICKQUE commented Aug 30, 2020

I also encountered the same type of error in the vscode and go plugins
my go env

set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\admin\AppData\Local\go-build
set GOENV=C:\Users\admin\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\Go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=D:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\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\admin\AppData\Local\Temp\go-build384423178=/tmp/go-build -gno-record-gcc-switches

The code in the workspace failed to compile (see the error message below). If you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new. 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

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Aug 30, 2020

@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.

@mrlay
Copy link

@mrlay mrlay commented Aug 31, 2020

@kittyhappy thanks your advice, which help solve it. @PICKQUE you can try create a *.code-workspace project files, and add the configurations which @kittyhappy adviced, may be the case would be solved.

@PICKQUE
Copy link

@PICKQUE PICKQUE commented Aug 31, 2020

@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.

i'm sure the root directory exist the go.mod and the go version is 1.15(i'm upgrade yesterday,but it's not work

@youguanxinqing
Copy link

@youguanxinqing youguanxinqing commented Sep 18, 2020

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.