go version)?$ go version go version go1.13 darwin/amd64
Yes
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"
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.
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.
I see the build .: cannot find module for path . error instead.
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._
Most helpful comment
My file structure is the following
Since I was running
go buildfrom the root directory (where thego.modfile resides) I was getting the above mentioned error. I needed to either rungo build cmd/myapp/main.go(which would result in amainexecutable in the root directory) orcd cmd/myapp && go build(which would result in an executable in themyappdirectory with the namemyapp)._Me? I know who I am: I'm a noob speaking to noobs who are willing to listen to other noobs._