go: question: "go: cannot find main module; see 'go help modules'"
What did you do?
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, world\n”) }
What did you expect to see?
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)
What did you see instead?
go: cannot find main module; see ‘go help modules’
Does this issue reproduce with the latest release (go1.12.5)?
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.
System details
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.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (4 by maintainers)
Commits related to this issue
- Make `go test` module awareness behave as before (go<=v1.15) Go v1.16 introduced module-aware commands by default. This version upgrade broke our http2 interop tests (see #25660). Setting the go envi... — committed to drfloob/grpc by drfloob 3 years ago
- Create a go module for http2 interop test, fixing breakage from upgrade to go v1.16 (#25707) Go v1.16 introduced module-aware commands by default. This version upgrade broke our http2 interop tests ... — committed to grpc/grpc by drfloob 3 years ago
After upgrade to go1.16, try to set :
go env -w GO111MODULE=autohttps://blog.golang.org/go116-module-changes
Thx
You probably still have
GO111MODULE=onset in your environment. If you’re using ash-like shell,unset GO111MODULEorexport GO111MODULE=autoshould put things back intoautomode.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
#generalchannel is a good starting point.Go Community on Hashnode with questions and posts tagged with “go”
The golang-nuts mailing list
IRC channel #go-nuts on Freenode
Thanks
work for me thanks !!!
This issue is closed, but it looks like a lot of people are seeing similar error messages since module-aware mode is now enabled by default in Go 1.16 (#41330).
I’ve opened #44745 to clarify the error messages. That should explain the problem and suggest a solution when possible. I’d like to backport that to the next 1.16 patch release.
Note that
go env -w GO111MODULE=autoprobably won’t work in Go 1.17. We plan to drop support for GOPATH builds and that environment variable.For vscode I have a workaround, do not know if this work for other editors.
My directory structure is:
opening “Somepoject1” in vscode causes a problem. To solve this I have made a second directory structure:
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