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: improve diagnostics for mod subcommands within $GOPATH/src #26365

Closed
davecheney opened this issue Jul 13, 2018 · 8 comments

Comments

Projects
None yet
5 participants
@davecheney
Copy link
Contributor

commented Jul 13, 2018

Please answer these questions before submitting your issue. Thanks!

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

% go version
go version devel +8a330454dc Fri Jul 13 03:53:00 2018 +0000 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

% go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/dfc/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/dfc"
GOPROXY=""
GORACE=""
GOROOT="/Users/dfc/go"
GOTMPDIR=""
GOTOOLDIR="/Users/dfc/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/by/3gf34_z95zg05cyj744_vhx40000gn/T/go-build891243944=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Daves-MacBook-Pro(~/src/github.com/pkg/errors) % go mod -init -module github.com/pkg/errors
go: creating new go.mod: module github.com/pkg/errors
Daves-MacBook-Pro(~/src/github.com/pkg/errors) % cat go.mod 
module github.com/pkg/errors
Daves-MacBook-Pro(~/src/github.com/pkg/errors) % go mod -verify
go mod: cannot use outside module

What did you expect to see?

Not a failure

What did you see instead?

All go mod commands report

go mod: cannot use outside module
@myitcv

This comment has been minimized.

Copy link
Member

commented Jul 13, 2018

@davecheney looks like you're running these commands from within your GOPATH?

In which case, take a look through @rsc's answer in golang-dev:

https://groups.google.com/d/msg/golang-dev/a5PqQuBljF4/tYBmxfF4BgAJ

You'll need to set GO111MODULE=on to force module mode if you want to work with modules inside your GOPATH.

@myitcv myitcv added the modules label Jul 13, 2018

@davecheney

This comment has been minimized.

Copy link
Contributor Author

commented Jul 13, 2018

@myitcv

This comment has been minimized.

Copy link
Member

commented Jul 13, 2018

@rsc @bcmills is it worth adding GO111MODULE to go env to help in these sorts of situations?

Feels like that might be a very common first question we'll ask people.

@davecheney

This comment has been minimized.

Copy link
Contributor Author

commented Jul 13, 2018

@bcmills

This comment has been minimized.

Copy link
Member

commented Jul 13, 2018

I suspect we should do both of those things. 🙂

@bcmills bcmills changed the title cmd/go: cannot use outside module after go mod -init cmd/go: improve diagnostics for mod subcommands within $GOPATH/src Jul 13, 2018

@bcmills bcmills added the NeedsFix label Jul 16, 2018

@FiloSottile

This comment has been minimized.

Copy link
Member

commented Jul 17, 2018

We should also show a helpful error for failed builds when a go.mod file was found and modules are off because of GOPATH.

@gopherbot

This comment has been minimized.

Copy link

commented Jul 18, 2018

Change https://golang.org/cl/124708 mentions this issue: cmd/go: diagnose 'go mod' in GOPATH/src better

@gopherbot gopherbot closed this in 764d0bb Jul 19, 2018

@bcmills

This comment has been minimized.

Copy link
Member

commented Jul 19, 2018

Should be much improved now. Please reopen if you still run into confusing behavior.

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