Go: question: "go: cannot find main module; see 'go help modules'"

Created on 13 May 2019  路  6Comments  路  Source: golang/go

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, worldn")
}

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

Most helpful comment

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.

All 6 comments

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

natefinch picture natefinch  路  3Comments

Miserlou picture Miserlou  路  3Comments

rsc picture rsc  路  3Comments

jayhuang75 picture jayhuang75  路  3Comments

OneOfOne picture OneOfOne  路  3Comments