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

go generate gives missing go sum entry for module errors #1483

Closed
peter9207 opened this issue Mar 10, 2021 · 25 comments
Closed

go generate gives missing go sum entry for module errors #1483

peter9207 opened this issue Mar 10, 2021 · 25 comments

Comments

@peter9207
Copy link

What happened?

running go generate ./...
gives go package errors

../../../../../go/pkg/mod/github.com/99designs/[email protected]/cmd/gen.go:9:2: missing go.sum entry for module providing package github.com/urfave/cli/v2
../../../../../go/pkg/mod/github.com/99designs/[email protected]/internal/imports/prune.go:15:2: missing go.sum entry for module providing package golang.org/x/tools/go/ast/astutil
../../../../../go/pkg/mod/github.com/99designs/[email protected]/internal/code/packages.go:8:2: missing go.sum entry for module providing package golang.org/x/tools/go/packages
../../../../../go/pkg/mod/github.com/99designs/[email protected]/internal/imports/prune.go:16:2: missing go.sum entry for module providing package golang.org/x/tools/imports
graph/resolver.go:3: running "go": exit status 1

if i run go get on each of these dependencies the error goes away and i can generate files just fine, but they come back after 1-2 days. so its quite annoying to keep having to run these.

I've spoken to a couple of people who used gqlgen before and none of them had any problems so I'm sure its not a super big deal. But just looking to get some help to get rid of these errors.

What did you expect?

go generate to generate the files without these errors

Minimal graphql.schema and models to reproduce

this happens with even the default generated schema

versions

  • gqlgen version? v0.13.0
  • go version? go1.16beta1 darwin/arm64
  • dep or go modules? go modules
@jaanreinok
Copy link

In my case I get next error in gitlab runner:
../.cache/pkg/mod/github.com/99designs/[email protected]/cmd/gen.go:9:2: missing go.sum entry for module providing package github.com/urfave/cli/v2 (imported by github.com/99designs/gqlgen/cmd); to add: go get github.com/99designs/gqlgen/[email protected]
What I have done without any results:
cleaned gitlab runner cache. Upped version gqlgen version, ran go mod tidy.
go 15

@peter9207
Copy link
Author

upon further debugging it seems that when i manually run go get it adds them to my go.mod file. which is why the error disappears. but when i run go mod tidy it cleans up these dependencies cuz i dont use them anywhere. and i get the error again.

@jaanreinok
Copy link

In my gitlab ci i fixed build issue like this. Second line might not be relevant for you.

- go get github.com/99designs/gqlgen/[email protected] && go run github.com/99designs/gqlgen
- go run github.com/markbates/pkger/cmd/pkger

@rokjoana
Copy link

rokjoana commented Mar 23, 2021

I'm experiencing the same problem with g1.16. I usually run via go run github.com/99designs/gqlgen generate and it gives me with the same error with version 0.12.2

../../go/pkg/mod/github.com/99designs/[email protected]/cmd/gen.go:9:2: missing go.sum entry for module providing package github.com/urfave/cli/v2 (imported by github.com/99designs/gqlgen/cmd); to add:
        go get github.com/99designs/gqlgen/[email protected]

I also can install the missing dependency with go get but if I want to update other dependencies in the project with go mod tidy it disappears from go.sum

@JonasDoe
Copy link
Contributor

I figure that's a general bug in Go 1.16: golang/go#44129 - I have troubles with other dependencies, too.

@Matts966
Copy link

@JonasDoe @peter9207
Thank you for tracking. This may be resolved by closed by golang/go#44129 (comment).

@quangthe
Copy link

quangthe commented Sep 9, 2021

I figure that's a general bug in Go 1.16: golang/go#44129 - I have troubles with other dependencies, too.

I use Go 1.17 and have the same issue.

@altanozlu
Copy link

Same with go 1.17

@altanozlu
Copy link

Deleting go.sum fixed it.

@avi94
Copy link

avi94 commented Oct 6, 2021

Same issue here by the way, using gqlgen version 0.14.0, and Go version 1.17. No matter what, none of the solutions mentioned above work. Completely confused as to what the issue is!

Any help would be greatly appreciated!

@juddbaguio
Copy link

Same issue here.

@ghost
Copy link

ghost commented Oct 11, 2021

Something that works for me regarding the missing cmd package: in resolver.go, before the line //go:generate go run github.com/99designs/gqlgen, add //go:generate go get github.com/99designs/gqlgen/[email protected]. It's not pretty because from what I can see it installs this package only for it to get removed again, but - at least for me - it works so far.

@molon
Copy link

molon commented Oct 15, 2021

import _ "github.com/99designs/gqlgen/cmd"
in your server.go or any other go files.

@oneuid
Copy link

oneuid commented Oct 18, 2021

I fixed with "go get -u github.com/99designs/gqlgen/cmd"

@Vovcharaa
Copy link

Vovcharaa commented Oct 21, 2021

Before every run of go generate ./... I need to run go get -d github.com/99designs/gqlgen to fix this issue.
Adding //go:generate go get -d github.com/99designs/gqlgen before //go:generate go run github.com/99designs/gqlgen seems to work fine.

@juddbaguio
Copy link

Before every run of go generate ./... I need to run go get -d github.com/99designs/gqlgen to fix this issue. Adding //go:generate go get -d github.com/99designs/gqlgen before //go:generate go run github.com/99designs/gqlgen seems to work fine.

Where should I add the following "//go:generate ..."?

@ghost
Copy link

ghost commented Oct 26, 2021

When you follow the tutorial, you end up with a folder graph and a file resolver.go inside it. In it, you add //go:generate go run github.com/99designs/gqlgen and to make it work, you add //go:generate go get github.com/99designs/gqlgen/[email protected] right before that. For reference, this is how my resolver.go looks like:

package graph

//go:generate go get github.com/99designs/gqlgen/[email protected]
//go:generate go run github.com/99designs/gqlgen

type Resolver struct{}

@peteole
Copy link

peteole commented Nov 8, 2021

Actually this from the introduction page fixed it for me, even though I did not have the time to find out what it's actually doing:

printf '// +build tools\npackage tools\nimport _ "github.com/99designs/gqlgen"' | gofmt > tools.go
go mod tidy

hc100 added a commit to hc100/nobolist that referenced this issue Dec 22, 2021
@skaji skaji mentioned this issue Mar 2, 2022
@frederikhors
Copy link
Collaborator

Can we close this? @mtibben @peteole?

@Diabolarius
Copy link

Actually, I believe not. All here is just workarounds. The problem seems in the generate script and the package handling of gqlgen itself rooted.
The reference of the packages seems not to be correct in gqlgen, therefore the generate execution/mod tidy removes these three packages each time during generation. Therefore they need to be installed/added manually or semi-automatically each time before the generation can run. This is not intended behavior. The referencing of the packages should be cleaned up, so the packages remain in the go.sum after gqlgen generate was executed.

@frederikhors
Copy link
Collaborator

@Diabolarius what you're saying is not on my projects. Can you create a repro? I'll be happy to help you.

@frederikhors
Copy link
Collaborator

Please write here if the problem persists.

@kateile
Copy link

kateile commented Mar 21, 2022

This works for me though I don't know what it does

go run -mod=mod github.com/99designs/gqlgen generate

@iamchubko
Copy link

This works for me though I don't know what it does

go run -mod=mod github.com/99designs/gqlgen generate

https://go.dev/ref/mod

The -mod=mod flag instructs the go command to attempt to find new modules providing missing packages and to update go.mod and go.sum. The go get and go mod tidy commands do this automatically.

And yeah, it helped me, too

@juanjoseluisgarcia
Copy link

This works for me though I don't know what it does

go run -mod=mod github.com/99designs/gqlgen generate

THIS IS THE ANSWER. Without this the packet do not work

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