6

I'm running into an error where vendor packages are not being correctly resolved by go; on macOS High Sierra 10.13.6. I'll use github.com/gorilla/mux as an example package

$ echo $GOPATH
/Users/gregorysims/go

$ go version
go version go1.11 darwin/amd64 

$ 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-build409352678=/tmp/go-build -gno-record-gcc-switches -fno-common"

I'm importing the package with

import (
    ...
    "github.com/gorilla/mux"
    ...
)

When running:

go build -o out main.go

I get the following error for each package in vendor

main.go:6:2: cannot find package "_/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux" in any of:
/usr/local/go/src/_/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux (from $GOROOT)
/Users/gregorysims/go/src/_/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux (from $GOPATH)

The folder should be found at

/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux

and is present in the directory.

Why is this being prefixed the following?

/Users/gregorysims/go/src/_

UPDATE

After deleting the local project and recloning from remote, I attempted to build without having any of the dependencies downloaded. This had the expected output:

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)

The above error is produced only after the build command is run after dep ensure is run.

UPDATE 2

Creating an empty vendor directory changes the output to:

main.go:6:2: cannot find package "github.com/gorilla/mux" in any of:
/Users/gregorysims/go/src/site/user/project/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)

Update 3

To simulate dep I called go get github.com/gorilla/mux followed by:

mv $GOPATH/src/github.com/gorilla/mux $GOPATH/src/site/user/project/vendor/github.com/gorilla/mux

After doing so, the problem surfaces again.

Gregory Sims
  • 511
  • 7
  • 18

0 Answers0