dep fails with root project import: xxx not in GOPATH

Created on 27 Jul 2017  Â·  19Comments  Â·  Source: golang/dep

What version of Go (go version) and dep (git describe --tags) are you using?

go version go1.8 linux/amd64

$ cd src/github.com/golang/dep/
$ git describe --tags
v0.1.0-295-gd558b52

$ export | grep GO
GOPATH=/home/kmutch/example
GORACE='halt_on_error=1 history_size=7'
GOROOT=/home/kmutch/go

what commands did you run before running dep?

$ git clone https://github.com/caarlos0/example.git
Cloning into 'example'...
$ cd example
$ export GOPATH=pwd
$ export PATH=$GOPATH/bin:$PATH
$ make setup
go get -u github.com/alecthomas/gometalinter
go get -u github.com/golang/dep/...
go get -u github.com/pierrre/gotestcover
go get -u golang.org/x/tools/cmd/cover
dep ensure
root project import: /home/kmutch/example not in GOPATH
Makefile:6: recipe for target 'setup' failed
make: * [setup] Error 1

What dep command did you run?

$ dep ensure
root project import: xxx not in GOPATH

What did you expect to see?

no errors and the dependencies downloaded into the vendor directory

What did you see instead?

root project import: xxxx not in GOPATH

I have also tried descending into subdirectories of the repo and running dep init from there to see if I can create the dep files, all to no avail.

I freely admit that GOPATH and its side effects are entirely and utterly beyond my comprehension.

feedback

Most helpful comment

most discussions tend to use shorthand that omits this for brevity, but "under GOPATH" really means "under the src directory under GOPATH", as all source code within GOPATH must be under $GOPATH/src/.

if you put your project at /Users/<user>/code/go/src/test_project, everything should work as expected.

All 19 comments

This was a GOPATH issue. It might be more appropriate to file a testy experience report. I despise, loath, and detest GOPATH.

The fix was to bury the go gettable software inside an artificial $GOPATH/src/[the project] directory and treat it as a component of a null project.

yeah, projects still have to be rooted within GOPATH, unfortunately. addressing that is something we do think we can do, but it's going to require toolchain changes. so we won't be able to really properly tackle it until we're working on translating dep into the toolchain 😢

I didn't understand the solution provided here.

Here is my GOPATH...

$ echo $GOPATH/
/Users/<user>/code/go/

If I create a /Users/<user>/code/go/test_project directory along with the following file:

package main

import (
    "errors"

    "github.com/Sirupsen/logrus"
)

func main() {
    logrus.Error(errors.New("whoops"))
}

If I look at /Users/<user>/code/go/src/github.com/... then I'll find the logrus dependency.

But now I call dep init from within /Users/<user>/code/go/test_project, then I see the error described in this issue.

But I don't understand the source of the problem?

most discussions tend to use shorthand that omits this for brevity, but "under GOPATH" really means "under the src directory under GOPATH", as all source code within GOPATH must be under $GOPATH/src/.

if you put your project at /Users/<user>/code/go/src/test_project, everything should work as expected.

Ah, thanks @sdboyer 🙂

An easy workaround is to build a dummy folder somewhere (export GOPATH=~/GOPATH) with a src folder inside and then add symlinks to your various projects under the src directory. Then you can CD through the links and dep init and dep ensure work as expected

I have the following error, seems the sym link doesn't work?

I have installed go and dep using brew

/Users/rjain/code/my_project/src
/Users/rjain/go/src
ln -s /Users/rjain/code/my_project /Users/rjain/go/src/
ls -la $GOPATH/src
my_project  -> /Users/rjain/code/my_project

cd /Users/rjain/code/my_project
export GOPATH=$HOME/go
dep init
ctx.DetectProjectGOPATH: /Users/rjain/my_project is not within a known GOPATH/src


@rjain15 https://github.com/golang/dep/issues/1146#issuecomment-328691231 may help clarify that a bit.

I can also verify that dep ensure does not work when the GOPATH is used as a symlink. My setup consists of the .go in my home folder. Because I have other projects and languages being used, I created a Projects folder which separates the different projects based on languages. Because I like having everything together in one place, I've symlinked the .go/src folder into the Projects/go folder. But it seems that despite the symlink actually being part of the .go/src path, it fails with this error. If I run dep ensure from the same folder from the actual path and not from within the symlink, it works fine.

Hope this info helps a bit.

FYI, we do builds of Go source code using Bazel. Bazel allows you to do builds outside of ~/go/src/<your-package> quite easily. Unfortunately, that means that we can't run dep if we check out the code elsewhere. This is why we use the following wrapper script around dep:

#!/bin/sh

export GOPATH="$(mktemp -d "/tmp/dep.XXXXXXXX")"
trap "rm -rf \"${GOPATH}\"" EXIT HUP INT

SRCDIR="${GOPATH}/src/fill-in-the-name-of-your-package-here"
mkdir -p "$(dirname "${SRCDIR}")"
ln -s "$(pwd)" "${SRCDIR}"
cd "${SRCDIR}"

dep "$@"

For those who is still in trouble getting rid of it hopefully this help, do not use a built in terminal in visual studio code if you installed go through gvm, use the bash or zsh terminal instead 🙂

we're actually going to have a workaround in the next release that should help with this: #1883

I despise, loath, and detest GOPATH.

any fix on this? i'm also getting

myProject is not within a known GOPATH/src

from rust cargo to go's dep, I am deeply depressed

from rust cargo to go's dep, I am deeply depressed

if you are undertaking a new project then go modules is the path you should follow.

any news on this ? I have been struggling with this issue I tried with simlinks and moving the project folder like this: src/my_project but it didn't work.

What technical limitation is preventing you from putting your code in the GOPATH? Hoping to understand the context WRT prioritization of things.

For me, it's that I create a symlink into a project folder that keeps all
my different language projects together and organized.

Running within the symlink folder is when I see the issue.

On Jan 22, 2019 10:56 PM, "Tim Heckman" notifications@github.com wrote:

What technical limitation is preventing you from putting your code in the
GOPATH? Hoping to understand the context WRT prioritization of things.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/golang/dep/issues/911#issuecomment-456691821, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AANH-FuQ_7sDarI69lZCSb6aDz3TT3_gks5vGAe1gaJpZM4Okp_u
.

Was this page helpful?
0 / 5 - 0 ratings