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

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?:

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 14
  • Comments: 17

Most upvoted comments

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.

$ 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

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

@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 - 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.

@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?