Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: cannot find main module root; see 'go help modules' #26639

Closed
yougg opened this issue Jul 27, 2018 · 9 comments

Comments

Projects
None yet
9 participants
@yougg
Copy link

commented Jul 27, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11beta2 linux/amd64

Does this issue reproduce with the latest release?

no

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/yougg/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/yougg/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build255031494=/tmp/go-build -gno-record-gcc-switches"

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.

# use the go1.11beta2 version
export PS1='\w \$'
cd ~/go
# if set GO111MODULE to 'off/auto' or unset it
# the go subcommands runs correct
~/go $echo $GO111MODULE

# but if set it to 'on', go subcommands runs error
~/go $export GO111MODULE=on
~/go $go version
go version go1.11beta2 linux/amd64
~/go $go bug
go: cannot find main module root; see 'go help modules'
~/go $go build
go: cannot find main module root; see 'go help modules'
~/go $go clean
go: cannot find main module root; see 'go help modules'
~/go $go doc
go: cannot find main module root; see 'go help modules'
~/go $go env
go: cannot find main module root; see 'go help modules'
~/go $go fix
go: cannot find main module root; see 'go help modules'
~/go $go fmt
go: cannot find main module root; see 'go help modules'
~/go $go generate
go: cannot find main module root; see 'go help modules'
~/go $go get
go: cannot find main module root; see 'go help modules'
~/go $go install
go: cannot find main module root; see 'go help modules'
~/go $go list
go: cannot find main module root; see 'go help modules'
~/go $go mod
go: cannot find main module root; see 'go help modules'
~/go $go run
go: cannot find main module root; see 'go help modules'
~/go $go test
go: cannot find main module root; see 'go help modules'
~/go $go tool
go: cannot find main module root; see 'go help modules'
~/go $go version
go version go1.11beta2 linux/amd64
~/go $go vet
go: cannot find main module root; see 'go help modules'

What did you expect to see?

the correct go subcommand output

What did you see instead?

# almost all go subcommands shows the same error
go: cannot find main module root; see 'go help modules'
@mvdan

This comment has been minimized.

Copy link
Member

commented Jul 27, 2018

You need to create a go.mod file to have a Go module. I'd suggest following the documentation to create a module.

@yougg

This comment has been minimized.

Copy link
Author

commented Jul 27, 2018

i don't think the go.mod is need when i run these commands anywhere, like: go doc builtin or go tool dist list
and whether or not the go.mod file exist, these commands should not output error go: cannot find main module root; see 'go help modules'

@mvdan

This comment has been minimized.

Copy link
Member

commented Jul 27, 2018

If your point is about how some subcomands like doc and env should not require a go.mod file outside of GOPATH, that may be a valid bug. I'll defer that to @rsc and @bcmills.

@oiooj oiooj added the modules label Jul 27, 2018

@mvdan mvdan added the NeedsDecision label Jul 28, 2018

@mvdan mvdan added this to the Go1.11 milestone Jul 28, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Jul 29, 2018

Change https://golang.org/cl/126655 mentions this issue: cmd/go: split go mod into multiple subcommands

@leighmcculloch

This comment has been minimized.

Copy link
Contributor

commented Aug 22, 2018

Even with the fix, using go1.11rc1 I'm seeing the error go: cannot find main module; see 'go help modules' when trying to go get outside of a module, to download and install a module. So it doesn't seem like this issue is fully resolved.

@chmike

This comment has been minimized.

Copy link

commented Aug 26, 2018

Seeing a similar error message with GO111MODULE=on.
When I try to execute go get -u -v github.com/ramya-rao-a/go-outline because visual studio code needs it, I get the error message go: cannot find main module; see 'go help modules'.

Does it mean that go-outline is missing a go.mod ? That would create a backward compatibility problem.

Nearly all (probably all) packages I use with visual studio code fail to install because of such error.

@tural-esger

This comment has been minimized.

Copy link

commented Sep 12, 2018

I am getting this error too

@agnivade

This comment has been minimized.

Copy link
Member

commented Sep 12, 2018

We do not discuss on closed issues. Looks like you are hitting #27380. If you think it is a new error, please open a new issue.

Thank you.

@QuietWind

This comment has been minimized.

Copy link

commented Dec 12, 2018

Delete GO111MODULE=on, and work fine

@golang golang locked as resolved and limited conversation to collaborators Dec 12, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.