Go: cmd/go: go clean fails in case of no Go source and enabling Go Modules

Created on 22 Mar 2019  路  3Comments  路  Source: golang/go

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

$ go version
go version devel +4906a00cdd Fri Mar 22 09:07:09 2019 +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 Output

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/lufia/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lufia"
GOPROXY=""
GORACE=""
GOROOT="/Users/lufia/go"
GOTMPDIR=""
GOTOOLDIR="/Users/lufia/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/lufia/go/src/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/0b/8y9l7z3x1pv4p2c5l9f0y6600000gn/T/go-build395440320=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

If GO111MODULE=on and there is no Go source file in current directory, go clean fails.

$ git clone https://github.com/lufia/go-mod-clean
$ cd go-mod-clean

$ export GO111MODULE=off
$ go clean && echo ok
ok

$ export GO111MODULE=on
$ go clean && echo ok
can't load package: package github.com/lufia/go-mod-clean: unknown import path "github.com/lufia/go-mod-clean": cannot find module providing package github.com/lufia/go-mod-clean

$ go clean ./... && echo ok
ok

What did you expect to see?

I want that go clean is success.

What did you see instead?

I have seen an error message above.

NeedsInvestigation modules

Most helpful comment

I hope go clean become same status either GO111MODULE is set to on or not.

I have a Makefile that like described below:

.PHONY: clean
clean:
    go clean

A user that use GOPATH mode above recipe works fine. But now, above Makefile will fail with "cannot find module providing package..." by switching to module-aware mode.

All 3 comments

@bcmills @jayconrod

What did you expect go clean to do in that case? It normally deletes a bunch of legacy files from the current package, but if you're using modules it is unlikely that you have any of those legacy files around.

(Note that both go clean -modcache and go clean -cache now avoid resolving imports, so this issue should only apply to go clean without additional flags.)

I hope go clean become same status either GO111MODULE is set to on or not.

I have a Makefile that like described below:

.PHONY: clean
clean:
    go clean

A user that use GOPATH mode above recipe works fine. But now, above Makefile will fail with "cannot find module providing package..." by switching to module-aware mode.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michaelsafyan picture michaelsafyan  路  3Comments

natefinch picture natefinch  路  3Comments

longzhizhi picture longzhizhi  路  3Comments

jayhuang75 picture jayhuang75  路  3Comments

Miserlou picture Miserlou  路  3Comments