0

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/consul@v0.0.0-20171026175957-610f3c86a089/api)
    github.com/hashicorp/consul/api v1.15.2 (/root/go/pkg/mod/github.com/hashicorp/consul/api@v1.15.2)

I tried installing one version module separately:

go get github.com/hashicorp/consul/api@v1.15.2

Also:

go mod download /root/go/pkg/mod/github.com/hashicorp/consul@v0.0.0-20171026175957-610f3c86a089/api
/root/go/pkg/mod/github.com/hashicorp/consul@v0.0.0-20171026175957-610f3c86a089/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

milenao
  • 707
  • 1
  • 6
  • 8

2 Answers2

1

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/consul@v0.0.0-20171026175957-610f3c86a089. 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.

Zeke Lu
  • 6,349
  • 1
  • 17
  • 23
-3

The error message you're encountering indicates that there are multiple modules in your Go project that contain the import github.com/hashicorp/consul/api, causing ambiguity. To resolve this issue, you can try one of the following solutions:

  1. Vendor Dependencies: If your project is using Go modules, ensure that you have a consistent and updated go.mod file that correctly specifies the required dependencies. If you have a vendor directory in your project, make sure it contains the correct version of the github.com/hashicorp/consul/api package.

To update the dependencies, navigate to your project's root directory and execute the following command:

go mod tidy

If you have a vendor directory, you can update it by running

go mod vendor
  1. Remove Duplicate Modules: Check if you have multiple modules in your project that import github.com/hashicorp/consul/api. If you have nested modules or conflicting dependencies, remove or resolve them to have a single consistent import statement for github.com/hashicorp/consul/api.

  2. Update the Import Path: Verify that the import path github.com/hashicorp/consul/api is correct and corresponds to the intended package you want to use. If necessary, update the import path to the correct version or module.

You can use the go get command to update or install the package explicitly:

go get -u github.com/hashicorp/consul/api
  1. Analyze and Resolve Module Dependencies: If the issue persists, it's possible that other modules in your project have conflicting dependencies or import statements. Analyze the dependencies of your project and ensure they are compatible and correctly resolved.

You can use the go mod graph command to view the module graph and identify any conflicting or redundant dependencies.

Additionally, consider using Go's versioning features (go.mod file) to specify the specific versions or ranges of dependencies your project requires, ensuring compatibility between modules

With this you should be able to solve your issue