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

Golang Lru type parameter requires go1.18 or later #2576

Closed
crcortesd opened this issue Mar 3, 2023 · 11 comments
Closed

Golang Lru type parameter requires go1.18 or later #2576

crcortesd opened this issue Mar 3, 2023 · 11 comments

Comments

@crcortesd
Copy link

What happened?

Hi, i just tried installing the library and after running go run ./server.go im getting the following errors

../pkg/mod/github.com/hashicorp/golang-lru/[email protected]/simplelru/list.go:8:12: type parameter requires go1.18 or later (-lang was set to go1.16; check go.mod)
../pkg/mod/github.com/hashicorp/golang-lru/[email protected]/simplelru/list.go:8:14: predeclared comparable requires go1.18 or later (-lang was set to go1.16; check go.mod)
../pkg/mod/github.com/hashicorp/golang-lru/[email protected]/simplelru/list.go:8:28: predeclared any requires go1.18 or later (-lang was set to go1.16; check go.mod)
../pkg/mod/github.com/hashicorp/golang-lru/[email protected]/simplelru/list.go:14:19: type instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)

and so on, until im getting the too many errors message

I got it to work by reversing #2570 update though

versions

  • v0.17.25?
  • go version go1.20.1 darwin/amd64?
@StevenACoffman
Copy link
Collaborator

I suspect you need a go.mod file in the place where your server.go file is located, and it should specify Go 1.18.

As of the Go 1.17 release, if the go directive is missing, go 1.16 is assumed

@StevenACoffman
Copy link
Collaborator

I cannot otherwise reproduce this problem on darwin/amd64 with Go 1.20.1, so I'm going to close this issue for now.

@cdavis09
Copy link

I am still seeing this issue. Testing with 1.18.10, 1.19.7 and 1.20.2.

I can also confirm that after removing #2570 it works with all 3.

@StevenACoffman
Copy link
Collaborator

@cdavis09 I suspect your problem is caused by you running go run ./server.go in a directory without a go.mod file. If so, you need to run something like:

go mod init github.com/cdavis09/mygraph
go mod tidy
go run ./server.go

This would most likely solve what I imagine your problem is. If not, Can you provide a repository that demonstrates this issue? I am not able to reproduce it.

@cdavis09
Copy link

Hi @StevenACoffman, I did exactly as you suggested above. I initialized a clean project (e.g. go mod init ...) and followed the directions in the README to initialize gqlgen. I had the exact same issue for all 3 versions of go that I listed - tested just so I could say I did.

The only way to get it to run was by pulling a local copy of gqlgen, from version v0.17.26 and reverting the commit for #2570 and then forcing my local projects to use the local module for gqlgen.

Note that I tried it 2 ways once I established that it worked. I completely initialized a project using latest gqlgen to the point of running go run ./server.go and seeing the above errors. Then I replaced the dependency using my local copy. Go correctly complained about the version of the github.com/hashicorp/golang-lru dependency and once I got the go.sum for the earlier version reran it and it compiled and ran fine.

@StevenACoffman
Copy link
Collaborator

Hey, thanks very much for doing all that and clarifying, and I'm really sorry for this. I have to admit I'm somewhat stymied by not being able to reproduce this problem locally. Thanks for continuing to stick with it.

When you initialized a clean project with go mod init github.com/cdavis09/mygraph the go.mod file it creates has go 1.18 in it or go 1.16?

Can you also tell me what the output of go env is for you?

@cdavis09
Copy link

The go.mod file accurately sets the go value to version. In my case it was one of 1.18, 1.19 and 1.20.

Since I am primarily concerned with using go 1.20+ here's the go env for that version.

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="~/Library/Caches/go-build"
GOENV="~/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="~/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="~/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/kl/x9d4283x3_qd8b4q07v2d3040000gr/T/go-build3211474776=/tmp/go-build -gno-record-gcc-switches -fno-common"

Hope this helps!

@MansonLuo
Copy link

i have met same error, I happened to fix it.

I use vscode, I open project A in vscode, at the same time, I open terminal, enter project B, run go run ./server.go, expecting project B would work.

but not, it give me above error.

and then, In vscode I close project A, and open Project B, run same commands, it works.

it's so werid

@cdavis09
Copy link

cdavis09 commented Apr 4, 2023

I wanted to update that this is still an issue, at least when following the directions directly. After looking into it a little more (there's still some things going on I haven't had time to track down) I found a simple workaround.

With all of the above reported environment and versions the same, I can reproduce the failure 100% of the time. I looked into the cache and path resolution for the dependency on simplelru (from hashicorp/golang-lru), noting that GOPATH and cached versions still contained their respective go.mod files indicating go1.18 as expected.

But, if after running go run github.com/99designs/gqlgen init I ran go mod tidy again, it resolved the issue. Here's the diff from my go.mod file before and after running the extra go mod tidy

5c5,8
< require github.com/99designs/gqlgen v0.17.28
---
> require (
>       github.com/99designs/gqlgen v0.17.28
>       github.com/vektah/gqlparser/v2 v2.5.1
> )
9a13,15
>       github.com/gorilla/websocket v1.5.0 // indirect
>       github.com/hashicorp/golang-lru/v2 v2.0.1 // indirect
>       github.com/mitchellh/mapstructure v1.5.0 // indirect
12d17
<       github.com/vektah/gqlparser/v2 v2.5.1 // indirect

As you can see, it moved gqlparser alongside gqlgen in the separate "direct dependency" block and added an indirect entry for golang-lru, websocket and mapstructure. By bringing in golang-lru suddenly - the error goes away and it compiles and runs just fine.

And glancing at the binary (using go build instead of go run) we can see it compiled the correct versions of the dependencies.

go version -m server
server: go1.20.2
	path	command-line-arguments
	dep	github.com/99designs/gqlgen	v0.17.28	h1:kbc1RhvwMltFVCb6drIrfQcxS9iKybyNwaJkgJZd5ao=
	dep	github.com/agnivade/levenshtein	v1.1.1	h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=

	dep	github.com/gorilla/websocket	v1.5.0	h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
	dep	github.com/hashicorp/golang-lru/v2	v2.0.1	h1:5pv5N1lT1fjLg2VQ5KWc7kmucp2x/kvFOnxuVTqZ6x4=
	dep	github.com/mitchellh/mapstructure	v1.5.0	h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
	dep	github.com/vektah/gqlparser/v2	v2.5.1	h1:ZGu+bquAY23jsxDRcYpWjttRZrUz07LbiY77gUOHcr4=

I don't know why this wasn't necessary before or why it's not necessary when you (@StevenACoffman) run the instructions in the README.md file or the docs tutorial, but this is where I'm at.

@StevenACoffman
Copy link
Collaborator

Oh wow. Ok, thanks.

So gqlgen generate currently runs Go mod tidy here:

if err = cfg.Packages.ModTidy(); err != nil {

Is it possible the config file sets SkipModTidy to true?

@cdavis09
Copy link

cdavis09 commented Apr 7, 2023

Hi Steven, no the config file does not set that value. I have been using the default file generated from the init command.

UnAfraid added a commit to UnAfraid/gqlgen that referenced this issue Jul 19, 2023
Added `go mod tidy` in quick start guide to address issues like 99designs#2717, 99designs#2651, 99designs#2641, 99designs#2614 and 99designs#2576
UnAfraid added a commit to UnAfraid/gqlgen that referenced this issue Jul 19, 2023
Added `go mod tidy` in quick start guide to address issues like 99designs#2717, 99designs#2651, 99designs#2641, 99designs#2614 and 99designs#2576
UnAfraid added a commit to UnAfraid/gqlgen that referenced this issue Jul 19, 2023
Added `go mod tidy` in quick start guide to address issues like 99designs#2717, 99designs#2651, 99designs#2641, 99designs#2614 and 99designs#2576
StevenACoffman pushed a commit that referenced this issue Jul 19, 2023
Added `go mod tidy` in quick start guide to address issues like #2717, #2651, #2641, #2614 and #2576
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants