Go install error: ambiguous import: found github.com/hashicorp/consul/api in multiple modules

117 Views Asked by At

I'm trying to install Levant but I'm getting the error:

go install github.com/hashicorp/levant
build github.com/hashicorp/levant: cannot load github.com/hashicorp/consul/api: ambiguous import: found github.com/hashicorp/consul/api in multiple modules:
    github.com/hashicorp/consul v0.0.0-20171026175957-610f3c86a089 (/root/go/pkg/mod/github.com/hashicorp/[email protected]/api)
    github.com/hashicorp/consul/api v1.15.2 (/root/go/pkg/mod/github.com/hashicorp/consul/[email protected])

I tried installing one version module separately:

go get github.com/hashicorp/consul/[email protected]

Also:

go mod download /root/go/pkg/mod/github.com/hashicorp/[email protected]/api
/root/go/pkg/mod/github.com/hashicorp/[email protected]/api: malformed module path "/root/go/pkg/mod/github.com/hashicorp/consul": empty path element

What do I need to install Levant without errors?

upd: I was able to install Levant by downloading the binaries, but I couldn't fix the error with go get/install: download binaries https://releases.hashicorp.com/levant/ and run unzip

1

There are 1 best solutions below

0
On

Try

go install github.com/hashicorp/levant@latest

See Compile and install packages and dependencies:

If the arguments have version suffixes (like @latest or @v1.0.0), "go install" builds packages in module-aware mode, ignoring the go.mod file in the current directory or any parent directory, if there is one. This is useful for installing executables without affecting the dependencies of the main module.

...

If the arguments don't have version suffixes, "go install" may run in module-aware mode or GOPATH mode, depending on the GO111MODULE environment variable and the presence of a go.mod file. See 'go help modules' for details. If module-aware mode is enabled, "go install" runs in the context of the main module.

BTW, the error message indicates that your main module (the current directory or any parent directory that contains a go.mod file) depends on a very old module github.com/hashicorp/[email protected]. A go.mod file is added to https://github.com/hashicorp/consul in 2019 (see this commit). You should upgrade this dependency for the main module. But if your purpose is to install the levant tool, you can ignore this issue now.