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

cannot find package hcl/hcl/printer #449

Closed
ionutnechita opened this issue Feb 24, 2021 · 4 comments
Closed

cannot find package hcl/hcl/printer #449

ionutnechita opened this issue Feb 24, 2021 · 4 comments
Labels
v1 Relates to the v1 line of releases

Comments

@ionutnechita
Copy link

cannot find package "github.com/hashicorp/hcl/hcl/printer" in any of:
/usr/lib/go-1.16/src/github.com/hashicorp/hcl/hcl/printer (from $GOROOT)
/root/go/src/github.com/hashicorp/hcl/hcl/printer (from $GOPATH)

@jmoodie2002
Copy link

Same issue while trying to install with cobra. Cobra posted solution has no effect. Ubuntu 18.04:

export GO111MODULE=on
go get -u github.com/spf13/cobra/cobra

package github.com/hashicorp/hcl/hcl/printer: cannot find package "github.com/hashicorp/hcl/hcl/printer" in any of:
/usr/lib/go-1.10/src/github.com/hashicorp/hcl/hcl/printer (from $GOROOT)
/home/xxx/go/src/github.com/hashicorp/hcl/hcl/printer (from $GOPATH

@apparentlymart
Copy link
Member

apparentlymart commented Feb 26, 2021

Hi @ionutnechita,

I'm sorry you've encountered this problem.

Based on your error messages, it seems like you are using Go 1.16 in the legacy GOPATH mode rather than in the current Go Modules mode. Because GOPATH mode doesn't understand versioning, it's unable to distinguish between HCL version 1 and HCL version 2, and so it's failing to access what looks to be a HCL version 1 dependency.

There's some more details on what's going on here in the Version Selection wiki page, but I think a shorter answer to this is that if you migrate your project to use Go Modules instead of the legacy GOPATH mode then installing those HCL version 1 packages should work.

Due to technical constraints of the modern Go toolchain, we can no longer support the legacy GOPATH mode for HCL 1 without continuing the high-friction workarounds we employed for the first year after publishing major version 2, which have been a significant cause of confusion for contributors. For that reason, I'm going to close this issue.

I understand that some are getting HCL 1 as a dependency only indirectly via Viper (possibly Viper also indirectly via Cobra); unfortunately various parts of the Go ecosystem are moving gradually and independently to the modules system and so for some people HCL is the first thing in their dependency tree to begin requiring Go Modules, and I understand that is inconvenient but sadly if it were not this codebase then before too long it would be some other codebase because GOPATH mode is being phased out. 😖 The Viper team has also produced a troubleshooting guide which includes this problem at the time of writing, and they are echoing my suggestion to upgrade to Go Modules.


@jmoodie2002 I see in your output that you are using Go 1.10, which I believe predates the introduction of the GO111MODULE environment variable (the 111 in it refers to Go 1.11). In your case, I think you'll need to upgrade to a newer version of Go in addition to enabling modules mode; Go 1.11 would be the minimum, but Go Modules was still experimental in that Go version and so you may encounter bugs and workflow friction that were addressed in later Go releases before Go Modules became the recommended solution.

@misteruly
Copy link

With GoPath, you can also avoid this mistake??

madrisan added a commit to madrisan/go-mattermost-notify that referenced this issue Jun 25, 2021
Fix the build error:

    cannot find package "github.com/hashicorp/hcl/hcl/printer" in any of:
        /usr/local/go/src/github.com/hashicorp/hcl/hcl/printer (from $GOROOT)
        /go/src/github.com/hashicorp/hcl/hcl/printer (from $GOPATH)

This is related to the removal ot the legacy GOPATH mode support in the
package as explained in the HCL issue #449:

    hashicorp/hcl#449 (comment)

Signed-off-by: Davide Madrisan <davide.madrisan@gmail.com>
@lordvalium
Copy link

Could not solve the problem. v2 seems to be very inconvenient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1 Relates to the v1 line of releases
Projects
None yet
Development

No branches or pull requests

5 participants