Having packages in vendor causes build to fail

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:

  1. Have a project with dependencies.

  2. 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

  1. Create a vendor folder using mkdir vendor

  2. 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

  1. Run go get github.com/gorilla/mux or dep ensure -add github.com/gorilla/mux

  2. Move $GOPATH/src/github.com/gorilla/mux to $GOPATH/src/github.com/briggybros/gotest/vendor/github.com/gorilla/mux if used go get

  3. 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?

Not sure, and can’t test, but shouldn’t this be …/vendor/github.com/gorilla/mux?

Yes, that is correct, it was just a typo in the original post.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.