I’m running go 1.11 on macOS High Sierra 10.13.6. When I install packages in the vendor directory of my project, go build
paths appear to become corrupted.
I have also tested this on go 1.7, 1.8, 1.9, and 1.10
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gregorysims/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/gregorysims/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/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/tb/6c5vksm558q5q4t0fxfscgy80000gp/T/go-build368914193=/tmp/go-build -gno-record-gcc-switches -fno-common"
To reproduce:
-
Have a project with dependencies.
-
Run
go build
get the output:
$ go build -o out main.go
main.go:6:2: cannot find package "github.com/gorilla/mux" in any of:
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/Users/gregorysims/go/src/github.com/gorilla/mux (from $GOPATH)
as expected
-
Create a vendor folder using
mkdir vendor
-
Run
go build
get the output:
main.go:6:2: cannot find package "github.com/gorilla/mux" in any of:
/Users/gregorysims/go/src/github.com/briggybros/gotest/vendor/github.com/gorilla/mux (vendor tree)
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/Users/gregorysims/go/src/github.com/gorilla/mux (from $GOPATH)
as expected
-
Run
go get github.com/gorilla/mux
ordep ensure -add github.com/gorilla/mux
-
Move
$GOPATH/src/github.com/gorilla/mux
to$GOPATH/src/github.com/briggybros/gotest/vendor/github.com/gorilla/mux
if usedgo get
-
Run
go build
get the output:
main.go:6:2: cannot find package "_/Users/gregorysims/go/src/github.com/briggybros/gotest/vendor/github.com/gorilla/mux" in any of:
/usr/local/go/src/_/Users/gregorysims/go/src/github.com/briggybros/gotest/vendor/github.com/gorilla/mux (from $GOROOT)
/Users/gregorysims/go/src/_/Users/gregorysims/go/src/github.com/briggybros/gotest/vendor/github.com/gorilla/mux (from $GOPATH)
Why has the presence of the package changed where go is looking for it?