If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
creating a file hello.go in /home/ubuntu/go/src/hello/
package main
import "fmt"
func main() {
fmt.Printf("hello, worldn")
}
go into /home/ubuntu/go/src/hello/
call go build
now i expected an created file hello (in go on windows it was hello.exe)
go: cannot find main module; see 'go help modules'
every time (but only under ubuntu@DESKTOP windows sub system. After installing go on windows directly, all was working fine. I was able to call go build and an hello.exe was created. After calling hello.exe an hello was printed out on cmd. But now under ubunto on wsl i can call go version, go get, go list... but go build throw this "go: cannot find main module; see 'go help modules'" error. I try to delete export GO111MODULE=on in .profile, but this issue is still here.
go version go1.12.2 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ubuntu/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ubuntu/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOROOT/bin/go version: go version go1.12.2 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.12.2
uname -sr: Linux 4.4.0-17763-Microsoft
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.27-3ubuntu1) stable release version 2.27.
@jayconrod @bcmills
I try to delete export GO111MODULE=on in .profile, but this issue is still here.
You probably still have GO111MODULE=on
set in your environment. If you're using a sh
-like shell, unset GO111MODULE
or export GO111MODULE=auto
should put things back into auto
mode.
Timed out in state WaitingForInfo. Closing.
(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)
I am having the exact same problem. Have unset the environment variable. Also tried with auto, nothing changes. We have monorepo here, so it's only one go.mod in the root for the entire project. I imagine this is causing the confusion? Any ideas on how to debug this?
Hello @marcelotoledo, unlike other projects, we do not use the issue tracker for questions such as these. It is only used for bugs and feature proposals. Please feel free to ask it in any of these forums below:
Stack Overflow with questions tagged "go"
The Go Forum, a web-based forum
Gophers Slack, use the invite app for access. The #general
channel is a good starting point.
Go Community on Hashnode with questions and posts tagged with "go"
IRC channel #go-nuts on Freenode
Thanks
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:
Someproject1
Someproject2
If i start working on a project I open the respective directory in "Workspace"s in vscode. There I add al the microservice directories from the corresponding project directory in "Projects" to the workspace.
it's a little bit of work to setup but it works.
no errors any more
Most helpful comment
You probably still have
GO111MODULE=on
set in your environment. If you're using ash
-like shell,unset GO111MODULE
orexport GO111MODULE=auto
should put things back intoauto
mode.