"ambiguous import"-error when trying to "go get" cobra
BeyondEvil opened this issue ยท 9 comments
When following the installation instructions, I get:
$ go get -u github.com/spf13/cobra/cobra
go: github.com/spf13/cobra/cobra upgrade => v0.0.0-20200826151851-02a0d2fbc9e6
go get github.com/spf13/cobra/cobra: ambiguous import: found package github.com/spf13/cobra/cobra in multiple modules:
github.com/spf13/cobra v1.0.0 (/Users/jimbrannlund/go/pkg/mod/github.com/spf13/cobra@v1.0.0/cobra)
github.com/spf13/cobra/cobra v0.0.0-20200826151851-02a0d2fbc9e6 (/Users/jimbrannlund/go/pkg/mod/github.com/spf13/cobra/cobra@v0.0.0-20200826151851-02a0d2fbc9e6)
macOS Mojave 10.14.6
Darwin Jims-MacBook-Pro-2.local 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64
$ go version
go version go1.14.3 darwin/amd64
I'm using the new way with Go Modules, that is no GOPATH
Jims-MacBook-Pro-2:slack-cli jimbrannlund$ echo $GOPATH
Jims-MacBook-Pro-2:slack-cli jimbrannlund$
Directory contents:
Jims-MacBook-Pro-2:slack-cli jimbrannlund$ ls -la
total 56
drwxr-xr-x 8 jimbrannlund staff 256 Sep 3 09:54 .
drwxr-xr-x 49 jimbrannlund staff 1568 Sep 2 21:32 ..
drwxr-xr-x 13 jimbrannlund staff 416 Sep 2 21:33 .git
-rw-r--r-- 1 jimbrannlund staff 17 May 25 14:12 README.md
drwxr-xr-x 3 jimbrannlund staff 96 Sep 3 09:54 cmd
-rw-r--r-- 1 jimbrannlund staff 226 Sep 3 10:09 go.mod
-rw-r--r-- 1 jimbrannlund staff 13321 Sep 3 10:09 go.sum
-rw-r--r-- 1 jimbrannlund staff 1174 Sep 2 20:48 main.go
A workaround I found was to "go get" a specific version:
go get -u github.com/spf13/cobra/cobra@v1.0.0
A workaround I found was to "go get" a specific version:
go get -u github.com/spf13/cobra/cobra@v1.0.0
thanks for this, I'm building cobra as part of a distributed image and this works.
I've confirmed this has been resolved:
โฏ go get -u github.com/spf13/cobra
go: downloading github.com/spf13/cobra v1.0.0
go: github.com/spf13/cobra upgrade => v1.0.0
go: downloading github.com/spf13/pflag v1.0.3
go: github.com/spf13/pflag upgrade => v1.0.5
โฏ
I'm still having this issue:
$ go get -u github.com/spf13/cobra/cobra
go: github.com/spf13/cobra/cobra upgrade => v0.0.0-20200916152758-7f8e83d9366a
go get github.com/spf13/cobra/cobra: ambiguous import: found package github.com/spf13/cobra/cobra in multiple modules:
github.com/spf13/cobra v1.0.0 (/Users/myhome/go/pkg/mod/github.com/spf13/cobra@v1.0.0/cobra)
github.com/spf13/cobra/cobra v0.0.0-20200916152758-7f8e83d9366a (/Users/myhome/go/pkg/mod/github.com/spf13/cobra/cobra@v0.0.0-20200916152758-7f8e83d9366a)
macOS 10.15.7
Darwin Prime.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
$ go version
go version go1.15.2 darwin/amd64
Also using gomodules:
$ echo $GOPATH
$
The workaround works for me:
go get -u github.com/spf13/cobra/cobra@v1.0.0
But since this was closed as resolved I thought I'd bring it to y'all's attention.
I'm brand new to Go and started using go get
basically this week, so apologies if this is a case of PEBKAC.
@AndrewLivingston Your go get path is incorrect. There is no longer a package at cobra/cobra
. Only one single package at cobra
. So, you'll want to do:
go get -u github.com/spf13/cobra
And you should get the package correctly
I think I'm mixing up the command and the library here, sorry!
The main readme includes this section:
That "Here" links to: https://github.com/spf13/cobra/blob/master/cobra/README.md and does include the cobra/cobra path:
I have a feeling I'm still doing something wrong.
If it's not me, and it is the docs, I'd be happy to file a separate issue about that if there isn't one already.
Ah, it is me. The command was failing, I think, because I was inside a directory I'd already run go mod init inside of.