go version)?go version go1.15 windows/amd64
yes
go env)?go env Output
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\wwwAppData\Local\go-build
set GOENV=C:\Users\wwwAppData\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\wwwAppData\Local\Temp\go-build025204942=/tmp/go-build -gno-record-gcc-switches
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.
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
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.
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...
@mrlay: Please provide your gopls logs. Information on how to capture them can be found here.
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",
Glad you were able to solve it. I'm going to close this issue. @mrlay, please file a new issue to continue this discussion.
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\adminAppData\Local\go-build
set GOENV=C:\Users\adminAppData\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\adminAppData\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
@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.
@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: 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.
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
Looks like
GO111MODULE=onbut there is nogo.mod(i.e.GOMOD=NUL).
Please see golang/vscode-go#275 (comment) and make sure to open vscode from the folder withgo.modfile.
Wonderful! Solved my problem!
@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.
I have sloved this problem by using go mod init command ;
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
@wenchao5211: Please follow the steps in the troubleshooting guide and file a new issue so we can help you understand the problem.
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
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:
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:
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
Sorry, I got it resolved, but thank you very much!
---Original---
From: "D4v1dW3bb"<[email protected]>
Date: Tue, Nov 17, 2020 17:35 PM
To: "golang/go"<[email protected]>;
Cc: "Comment"<[email protected]>;"A7"<[email protected]>;
Subject: Re: [golang/go] x/tools/gopls: the code in the workspace failed to compile (#40790)
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
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
Most helpful comment
I have solved this question
I have solved this problem in vscode.In setting json,I add "go.buildOnSave": "workspace",