Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

dep fails with root project import: xxx not in GOPATH #911

Closed
karlmutch opened this issue Jul 27, 2017 · 19 comments
Closed

dep fails with root project import: xxx not in GOPATH #911

karlmutch opened this issue Jul 27, 2017 · 19 comments
Labels

Comments

@karlmutch
Copy link

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.

@karlmutch
Copy link
Author

karlmutch commented Jul 27, 2017

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.

@sdboyer
Copy link
Member

sdboyer commented Jul 27, 2017

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 😢

@Integralist
Copy link

Integralist commented Aug 16, 2017

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?

@sdboyer
Copy link
Member

sdboyer commented Aug 16, 2017

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.

@Integralist
Copy link

Ah, thanks @sdboyer 🙂

@AdamMcCormick
Copy link

AdamMcCormick commented Nov 14, 2017

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

@rjain15
Copy link

rjain15 commented Nov 30, 2017

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


@sdboyer
Copy link
Member

sdboyer commented Dec 3, 2017

@rjain15 #1146 (comment) may help clarify that a bit.

kingslef added a commit to kingslef/zally that referenced this issue Jan 9, 2018
Zally should be cloned in `$GOPATH/src`, and not to `$GOPATH`, as per
golang/dep#911. Otherwise dep won't work:

```
$ cd $GOPATH/github.com/zalando/zally/cli/zally/
$ dep ensure
root project import: $GOPATH/github.com/zalando/zally/cli/zally is not within any GOPATH/src
```

where as `$GOPATH/src/github.com/zalando/zally/cli/zally` does work with dep.
@jeffdupont
Copy link

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.

@EdSchouten
Copy link

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 "$@"

@afganhalbana
Copy link

afganhalbana commented Jul 1, 2018

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 🙂

@sdboyer
Copy link
Member

sdboyer commented Jul 1, 2018

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

@thefreeleo
Copy link

I despise, loath, and detest GOPATH.

@cmnstmntmn
Copy link

any fix on this? i'm also getting

myProject is not within a known GOPATH/src

@Swoorup
Copy link

Swoorup commented Jan 14, 2019

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

@karlmutch
Copy link
Author

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.

@ealipio
Copy link

ealipio commented Jan 23, 2019

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.

@theckman
Copy link
Collaborator

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

@jeffdupont
Copy link

jeffdupont commented Jan 23, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests