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 · 17 comments
Closed

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

kittyhappy opened this issue Aug 14, 2020 · 17 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
Contributor

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

@azi-v
Copy link

@azi-v azi-v commented Oct 28, 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 have sloved this problem by using go mod init command ;

@wenchao5211
Copy link

@wenchao5211 wenchao5211 commented Nov 3, 2020

When I was developing Golang with Vscode on MacOS, vscode prompt "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"
I have tried all the above solutions, but they still don't work. I am very upset. What should I do

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Nov 3, 2020

@wenchao5211: Please follow the steps in the troubleshooting guide and file a new issue so we can help you understand the problem.

@A7cc
Copy link

@A7cc A7cc commented Nov 17, 2020

I also have this problem. How can I solve it?
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

@D4v1dW3bb
Copy link

@D4v1dW3bb D4v1dW3bb commented Nov 17, 2020

Unsupported

Open a directory that contains a module in a subdirectory. gopls will not work in this case.

For vscode I have a workaround, do not know if this work for other editors.

My directory structure is:

Projects
  Someproject1
    microservice1
      go.mod
      go.sum
      main.go
    microservice2
      go.mod
      go.sum
      main.go
  Someproject2
  ...

opening "Somepoject1" in vscode causes a problem.
To solve this I have made a second directory structure:

Workspaces

If i start working on a project for the first time I open the respective directory in "Workspace"s in vscode. Then I save the workplace in the same place. Then I add al the microservice directories from the corresponding project directory in "Projects" to the workspace. When closing the workspace I save it.
If I want to start working on an existing workspace I choose open workspace and choose the right workspace file.

it's a little bit of work to setup but it works.

no errors any more

@A7cc
Copy link

@A7cc A7cc commented Nov 17, 2020

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