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:
Anything else we should know?:
👋 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! ❤️
Viper uses Go modules for managing its dependencies. Based on the error message Go looks for the package in your GOPATH.
$ 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
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.
@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!
@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?
@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.
@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.
As @mtarnawa pointed out: it's out of our hands (sadly).
Most helpful comment
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=onbefore running go get command. Otherwise, it tries fetching v2 of hcl which has no hcl/printer package anymore.