Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to get viper: Can not find "hashicorp/hcl/hcl/printer" #1076

Closed
rhishimagdum opened this issue Feb 11, 2021 · 17 comments
Closed

Failed to get viper: Can not find "hashicorp/hcl/hcl/printer" #1076

rhishimagdum opened this issue Feb 11, 2021 · 17 comments
Labels
resolution/invalid This doesn't seem right

Comments

@rhishimagdum
Copy link

Expected behavior (what you expected to happen):

Actual behavior (what actually happened):
$ go get github.com/spf13/viper
package github.com/hashicorp/hcl/hcl/printer: cannot find package "github.com/hashicorp/hcl/hcl/printer" in any of:
c:\go\src\github.com\hashicorp\hcl\hcl\printer (from $GOROOT)
C:\Users\sharma.yogesh\go\src\github.com\hashicorp\hcl\hcl\printer (from $GOPATH)
Repl.it link:

Code reproducing the issue:

go get github.com/spf13/viper

Environment:

  • Viper version:
  • Config source:
  • File format:

Anything else we should know?:

@rhishimagdum rhishimagdum added the kind/bug Something isn't working label Feb 11, 2021
@github-actions
Copy link

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news,
either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

@sagikazarmark sagikazarmark added resolution/invalid This doesn't seem right and removed kind/bug Something isn't working labels Feb 11, 2021
@sagikazarmark
Copy link
Collaborator

Viper uses Go modules for managing its dependencies. Based on the error message Go looks for the package in your GOPATH.

@yogi2606
Copy link

$ go get github.com/spf13/viper
package github.com/hashicorp/hcl/hcl/printer: cannot find package "github.com/hashicorp/hcl/hcl/printer" in any of:
c:\go\src\github.com\hashicorp\hcl\hcl\printer (from $GOROOT)
C:\Users\sharma.yogesh\go\src\github.com\hashicorp\hcl\hcl\printer (from $GOPATH)

what is solution for this someone help
@sagikazarmark closed the issue but its still occuring

@mtarnawa
Copy link

mtarnawa commented Feb 11, 2021

I'm assuming some people will end up here if they're fetching viper via golang Docker image, which by default does not utilize modules. So in Dockerfile, ensure you set:

ENV GO111MODULE=on

before running go get command. Otherwise, it tries fetching v2 of hcl which has no hcl/printer package anymore.

@sagikazarmark
Copy link
Collaborator

@yogi2606 it's not a viper issue. Please look up go modules in the Go documentation/wiki. You can probably solve it by setting the GO111MODULE=on env variable (and by using the latest Go version).

@mtarnawa thanks!

@Saurabh0707
Copy link

Saurabh0707 commented Feb 12, 2021

@sagikazarmark I understand we can upgrade to go modules or to the latest go version but what if we are not using go modules at all? Wouldn't software that's using viper break?

@mtarnawa
Copy link

mtarnawa commented Feb 12, 2021

@Saurabh0707 - there's nothing viper maintainers can do with this issue. This is stemming from go get downloading newer, incompatible version of Hashicorp's hcl which viper team can't control if you don't utilize modules.

@Saurabh0707
Copy link

Saurabh0707 commented Feb 12, 2021

@mtarnawa, Thanks, and yeah I get it. Like you and @sagikazarmark suggested, I will resolve the issue using go modules but that would be quite a significant change, switching to go modules. Kind of, technology architecture change for the software consuming viper.

@sagikazarmark
Copy link
Collaborator

As @mtarnawa pointed out: it's out of our hands (sadly).

@sebps
Copy link

sebps commented Apr 28, 2021

the following command worked for me :
env GO111MODULE=on go get github.com/spf13/cobra/cobra

@sergejzr
Copy link

env GO111MODULE=on go get github.com/spf13/cobra/cobra

Thank you!! This worked.

@lordvalium
Copy link

env GO111MODULE=on go get github.com/spf13/cobra/cobra

Thank you!! This worked.

For me unfortunately not
'env' is not recognized as an internal or external command,
operable program or batch file.

@xkortex
Copy link

xkortex commented Sep 14, 2021

@lordvalium Are you in a Windows shell? env is a POSIX-shell-ism. I'm not a Windows dude so I'm not sure how to set environment variables there, but it might be the set command.


I'm running into this issue in the ubuntu-latest github CI action.

Run go get -u github.com/maykonlf/semver-cli/cmd/semver
  go get -u github.com/maykonlf/semver-cli/cmd/semver
  shell: /usr/bin/bash -e {0}
cannot find package "github.com/hashicorp/hcl/hcl/printer" in any of:
	/opt/hostedtoolcache/go/1.15.15/x64/src/github.com/hashicorp/hcl/hcl/printer (from $GOROOT)
	/home/runner/go/src/github.com/hashicorp/hcl/hcl/printer (from $GOPATH)

Default go version :

go version go1.15.15 linux/amd64

I'm trying to install semver, which has a mod file, but it nonetheless failed to resolve the module correctly. I updated go to 1.16 using actions/setup-go and this succeeded. So you might just need to update your go version, and/or mess with GOROOT, GOPATH, and/or GO111MODULE.

      - uses: actions/setup-go@v2
        with:
          go-version: '1.16.7' # The Go version to download (if necessary) and use.

      - name: go get semver
        run: |
          go get -u github.com/maykonlf/semver-cli/cmd/semver

@nickname-nil
Copy link

以下命令对我有用: env GO111MODULE=on go get github.com/spf13/cobra/cobra

thank u

@reneINuvei
Copy link

I try env GO111MODULE=on go get github.com/spf13/cobra/cobra
but it doesn't work
can someone give me a solution

@parth-defy
Copy link

The following worked for me:
go mod init github.com/<package_name>
go mod tidy

@DanielPickens
Copy link

DanielPickens commented Oct 30, 2022

@parth-defy This adds go modules to the project: as @Saurabh0707 said, but doesn't solve the issue of Viper needing to add go modules to get viper package; this adds a go.mod file and upgrades dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests