mock icon indicating copy to clipboard operation
mock copied to clipboard

ERROR: cannot find module providing package go.uber.org/mock/mockgen/model: import lookup disabled by -mod=vendor

Open nebiros opened this issue 2 years ago • 9 comments

Actual behavior Moving from golang/mock I got this error when running the mockgen command and using reflection:

mockgen -build_flags=-mod=vendor -destination=internal/testing/mock/mock_dynamodbiface.go -package=mock github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface DynamoDBAPI
prog.go:12:2: cannot find module providing package go.uber.org/mock/mockgen/model: import lookup disabled by -mod=vendor
prog.go:12:2: cannot find module providing package go.uber.org/mock/mockgen/model: import lookup disabled by -mod=vendor
build flag -mod=vendor only valid when using modules
2023/09/11 16:50:04 Loading input failed: exit status 1

Expected behavior This doesn't happen with golang/mock module

To Reproduce

  1. go install go.uber.org/mock/mockgen@latest
  2. mockgen -build_flags=-mod=vendor -destination=internal/testing/mock/mock_dynamodbiface.go -package=mock github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface DynamoDBAPI

Additional Information

  • gomock mode (reflect or source): reflect
  • gomock version or git ref: v0.2.0
  • golang version: go version go1.21.1 darwin/arm64

Triage Notes for the Maintainers

nebiros avatar Sep 11 '23 22:09 nebiros

I ran into this same issue today 🐞 👍

jairogloz avatar Sep 19 '23 01:09 jairogloz

I'm getting similar errors without -mod=vendor. This started with v0.3.0.

It cannot find one of the application packages:

prog.go:14:2: no required module provides package gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/agentk/agentkapp: go.mod file not found in current directory or any parent directory; see 'go help modules'
prog.go:12:2: no required module provides package go.uber.org/mock/mockgen/model: go.mod file not found in current directory or any parent directory; see 'go help modules'
2023/09/21 03:52:18 Loading input failed: exit status 1
exit status 1

ash2k avatar Sep 21 '23 05:09 ash2k

I think it was a somewhat unrelated issue. I tried upgrading 0.2.0 -> 0.3.0 and at the same time adding -typed. It doesn't work this way, at least didn't work for me. I upgraded to 0.3.0 first and then now added -typed. Haven't finished fixing the tests, but mock generation succeeded. Sorry for the noise.

ash2k avatar Sep 21 '23 07:09 ash2k

The same problem that ash2k encountered also happens to me. This occurs when both v0.2.0 and v0.3.0 are installed in the same environment. The problem can be solved by uninstalling either one of these versions.

k-ken-t4g avatar Sep 28 '23 04:09 k-ken-t4g

Switching to source mode instead of reflect mode resolved this for me. I ultimately had to switch to source mode anyways as I'm using generics in my interfaces now that v0.3.0 has been released.

bradleygore avatar Oct 05 '23 18:10 bradleygore

If you are using reflect mode, just make sure that you have installed the same version of this package as the one defined in your go.mod.

danielmbirochi avatar Oct 28 '23 17:10 danielmbirochi

Make sure the mockgen version you installed is the same one in your go.mod

moeabdol avatar Nov 22 '23 07:11 moeabdol

I'm having this issue and the mockgen version is the same between the binary and our go.mod yet it keeps on failing. It works fine under macOS but on our containers it fails consistently. We are on v0.2.0 and cannot upgrade until https://github.com/uber-go/mock/issues/104 is fixed as it would cause massive churn in source control since we use an absolute path when specifying the output option, and everyone has a different home directory.

sodul avatar Jan 26 '24 22:01 sodul

It turns out that, one of the reasons, this fails is that on laptop we had copies of gomock_reflect_.... folders, and we had one accidentally added to source control a while back. Deleting the unwanted gomock_reflect_.... folder from source control removed the only go file that imported "go.uber.org/mock/mockgen/model" and then breaking our pipelines. Our fix was to add a test/mockgen_compat/main.go file that does nothing else but importing "go.uber.org/mock/mockgen/model" and the pipelines are happy again.

See https://github.com/golang/mock/issues/494#issuecomment-1365540087

sodul avatar Feb 07 '24 01:02 sodul