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

missing go.sum entry after ran go mod tidy #299

Closed
jackieli-tes opened this issue Jun 16, 2021 · 9 comments · Fixed by #353
Closed

missing go.sum entry after ran go mod tidy #299

jackieli-tes opened this issue Jun 16, 2021 · 9 comments · Fixed by #353

Comments

@jackieli-tes
Copy link

jackieli-tes commented Jun 16, 2021

You can use go bug to have a cool, automatically filled out bug template, or
fill out the template below.

Describe the bug

Following docs, after initial command wire, then after go mod tidy, subsequent go generate ./... reports:

/go/pkg/mod/github.com/google/wire@v0.5.0/cmd/wire/main.go:34:2: missing go.sum entry for module providing package github.com/google/subcommands (imported by github.com/google/wire/cmd/wire); to add:
        go get github.com/google/wire/cmd/wire@v0.5.0
/go/pkg/mod/github.com/google/wire@v0.5.0/cmd/wire/main.go:36:2: missing go.sum entry for module providing package github.com/pmezard/go-difflib/difflib (imported by github.com/google/wire/cmd/wire); to add:
        go get github.com/google/wire/cmd/wire@v0.5.0
/go/pkg/mod/github.com/google/wire@v0.5.0/internal/wire/copyast.go:21:2: missing go.sum entry for module providing package golang.org/x/tools/go/ast/astutil (imported by github.com/google/wire/internal/wire); to add:
        go get github.com/google/wire/internal/wire@v0.5.0
/go/pkg/mod/github.com/google/wire@v0.5.0/internal/wire/parse.go:30:2: missing go.sum entry for module providing package golang.org/x/tools/go/packages (imported by github.com/google/wire/internal/wire); to add:
        go get github.com/google/wire/internal/wire@v0.5.0
/go/pkg/mod/github.com/google/wire@v0.5.0/internal/wire/analyze.go:26:2: missing go.sum entry for module providing package golang.org/x/tools/go/types/typeutil (imported by github.com/google/wire/cmd/wire); to add:
        go get github.com/google/wire/cmd/wire@v0.5.0
wire_gen.go:3: running "go": exit status 1

To Reproduce

I use this command to reproduce the problem:

docker build - <<EOF
FROM golang
WORKDIR /myproject
RUN go mod init myproject

RUN echo '// +build wireinject' >> wire.go
RUN echo 'package main' >> wire.go
RUN echo 'import ("strings"; "github.com/google/wire")' >> wire.go
RUN echo 'func initReader(s string) *strings.Reader {' >> wire.go
RUN echo '	panic(wire.Build(strings.NewReader))' >> wire.go
RUN echo '}' >> wire.go

RUN go get github.com/google/wire/cmd/wire
RUN wire
RUN cat wire_gen.go
RUN go mod tidy
RUN cat go.mod
RUN go generate ./...
EOF

Expected behavior

go generate ./... should run without error

Version

go 1.16

github.com/google/wire v0.5.0

Additional context

Following the error message and run the suggest go get commands fixes the problem. But as soon as I run go mod tidy, go generate ./... reports error

@drscre
Copy link

drscre commented Jun 20, 2021

Possibly related to golang/go#44129

As a hack, you can run GOFLAGS=-mod=mod go generate ./...

@jackieli-tes
Copy link
Author

Possibly related to golang/go#44129

As a hack, you can run GOFLAGS=-mod=mod go generate ./...

I can confirm the workaround working

@drewolson
Copy link

FWIW, I think the "correct" work-around is to follow the advice here and create a tools.go file to track your development-only dependencies. This should resolve the go.sum problem and doesn't require setting GOFLAGS that introduce potentially unintuitive behavior.

@ccremer
Copy link

ccremer commented Sep 30, 2021

I have the same problem. I do have a tools.go file yet the go.sum entry is still missing after go mod tidy

// +build tools

// Place any runtime dependencies as imports in this file.
// Go modules will be forced to download and install them.
package tools

import (
	_ "github.com/google/wire"
)

(Go 1.16.7)

@drewolson
Copy link

// +build tools

// Place any runtime dependencies as imports in this file.
// Go modules will be forced to download and install them.
package tools

import (
	_ "github.com/google/wire"
)

(Go 1.16.7)

I believe this is because you need to be importing "github.com/google/wire/cmd/wire". This is the actual tool you use, not the library.

@ccremer
Copy link

ccremer commented Sep 30, 2021

you need to be importing "github.com/google/wire/cmd/wire".

Good catch!
This was the culprit, now it works.
Thanks a lot 🎉

@jackieli-tes
Copy link
Author

jackieli-tes commented Oct 1, 2021

Yes, I'm using the // +build tools workaround as well

There is some guidelines from here about tracking tools: https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module

And in my case importing github.com/google/wire/cmd/wire is enough. Full tools.go:

// +build tools

// following https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module

package main

import (
	_ "github.com/google/wire/cmd/wire"
)

@tx7do
Copy link

tx7do commented Oct 18, 2022

add import:

package tools

import (
	_ "github.com/google/subcommands"
)

then :

go mod tidy.

@manubu1012
Copy link

manubu1012 commented Aug 25, 2023

you can try go clean --modcache, then: go generate again

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

Successfully merging a pull request may close this issue.

6 participants