Go: build .: cannot find module for path .

Created on 7 Sep 2019  Β·  4Comments  Β·  Source: golang/go

What version of Go are you using (go version)?

$ go version
go version go1.13 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output

$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN="/Users/kush.patel/Projects/go/bin"
GOCACHE="/Users/kush.patel/Library/Caches/go-build"
GOENV="/Users/kush.patel/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=".hootops.com"
GONOSUMDB="
.hootops.com"
GOOS="darwin"
GOPATH="/Users/kush.patel/Projects/go"
GOPRIVATE="*.hootops.com"
GOPROXY="direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/kush.patel/Projects/user-info/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5m/7czshm113rv1wzt8r3cjt_hh0000gp/T/go-build523657452=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

In my go.mod I have for example
module go.hootops.com/hootsuite/user-info

My main func is inside a folder called "cmd/service"

When I run go tool cover -html=.coverage-reports/cover.out -o .coverage-reports/cover.html from where my go.mod file is (but not inside cmd/service, then I get

cover: cannot run go list: exit status 1
build .: cannot find module for path .

When I run go build . I get build .: cannot find module for path .
However, go build ./cmd/service works perfectly fine.

Furthermore, when the project is inside my GOPATH I do not have this error, only when it's outside. With module mode set to auto.

What did you expect to see?

I expected to see build fine and generate coverage report fine, I care more about getting this to work go tool cover -html=.coverage-reports/cover.out -o .coverage-reports/cover.html since I can build fine doing ./cmd/service.

What did you see instead?

I see the build .: cannot find module for path . error instead.

Most helpful comment

My file structure is the following

.
β”œβ”€β”€ README.md
β”œβ”€β”€ cmd
β”‚Β Β  └── myapp
β”‚Β Β      └── main.go
β”œβ”€β”€ go.mod
└── internal
 Β Β  β”œβ”€β”€ foo.go
  Β  └── bar.go

Since I was running go build from the root directory (where the go.mod file resides) I was getting the above mentioned error. I needed to either run go build cmd/myapp/main.go (which would result in a main executable in the root directory) or cd cmd/myapp && go build (which would result in an executable in the myapp directory with the name myapp).

_Me? I know who I am: I'm a noob speaking to noobs who are willing to listen to other noobs._

All 4 comments

I also cannot get more verbose output from go tool cover

I noticed in a different project, I can run go tool cover -html=.coverage-reports/cover.out -o .coverage-reports/cover.html and it would work. But go build . still errors.

Duplicate of #33855, closing. I worked around it for now by adding a unit test for anyone else running into this.

My file structure is the following

.
β”œβ”€β”€ README.md
β”œβ”€β”€ cmd
β”‚Β Β  └── myapp
β”‚Β Β      └── main.go
β”œβ”€β”€ go.mod
└── internal
 Β Β  β”œβ”€β”€ foo.go
  Β  └── bar.go

Since I was running go build from the root directory (where the go.mod file resides) I was getting the above mentioned error. I needed to either run go build cmd/myapp/main.go (which would result in a main executable in the root directory) or cd cmd/myapp && go build (which would result in an executable in the myapp directory with the name myapp).

_Me? I know who I am: I'm a noob speaking to noobs who are willing to listen to other noobs._

Was this page helpful?
0 / 5 - 0 ratings