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

Fails with import errors with modules on Go 1.11 #213

Closed
atombender opened this issue Aug 28, 2018 · 10 comments · Fixed by #218
Closed

Fails with import errors with modules on Go 1.11 #213

atombender opened this issue Aug 28, 2018 · 10 comments · Fixed by #218

Comments

@atombender
Copy link
Contributor

If I have a simple file such as this that refers to an imported package:

package mypackage
import "github.com/jackc/pgx"
// ...

then it fails with:

/Users/alex/.go/pkg/mod/github.com/jackc/[email protected]+incompatible/batch.go:6:2: could not import github.com/jackc/pgx/pgproto3 (cannot find package "github.com/jackc/pgx/pgproto3" in any of:
	/usr/local/opt/go/libexec/src/github.com/jackc/pgx/pgproto3 (from $GOROOT)
	/Users/alex/.go/src/github.com/jackc/pgx/pgproto3 (from $GOPATH))

In other words, it's looking for the source in the old location, not in $GOPATH/pkg/mod.

I'm able to reproduce this in a small Go program that uses golang.org/x/tools/go/loader to load files, and I can confirm that it does not work with Go modules. (E.g. see this issue for discussion.) Apparently the golang.org/x/tools/go/loader library has been superceded by golang.org/x/tools/go/packages, which is module-aware.

@atombender
Copy link
Contributor Author

@evanphx? This is a complete blocker on Go 1.11 with modules.

@mjlangan
Copy link

mjlangan commented Sep 4, 2018

We are seeing similar errors from mockery after trying Go 1.11 with modules

Generating mock for: Adapter in file: mocks/Adapter.go
/Users/michaell/go/src/golang.org/x/crypto/ssh/terminal/util.go:20:2: could not import golang.org/x/sys/unix (cannot find package "golang.org/x/sys/unix" in any of:
    /usr/local/go/src/golang.org/x/sys/unix (from $GOROOT)
    /Users/michaell/go/src/golang.org/x/sys/unix (from $GOPATH))
/Users/michaell/go/pkg/mod/github.com/!sirupsen/[email protected]/terminal_bsd.go:6:8: could not import golang.org/x/sys/unix (cannot find package "golang.org/x/sys/unix" in any of:
    /usr/local/go/src/golang.org/x/sys/unix (from $GOROOT)
    /Users/michaell/go/src/golang.org/x/sys/unix (from $GOPATH))
...

go mod vendor does pull these dependencies into the repository's /vendor/ folder, but it appears that mockery doesn't look there for dependencies when generating mocks.

@euskadi31
Copy link

Any news ? This prevents us to use mockery. Thx !

@bliuchak
Copy link

Is there any working alternative for Go 1.11 with modules?

@euskadi31
Copy link

@bliuchak yes, I use Docker...

Dockerfile.generate

FROM golang:1.10-alpine
RUN apk --no-cache --update add git make
RUN mkdir -p /go/src/github.com/your-name/your-service
WORKDIR /go/src/github.com/your-name/your-service
RUN go get github.com/vektra/mockery/.../
CMD ["make", "inner-generate"]

Makefile

inner-generate:
	@go get ./...
	@go generate ./...

generate-builder:
	@docker build -f Dockerfile.generate -t your-service-generate .

generate: generate-builder
	@# hack for https://github.com/vektra/mockery/issues/213
	@echo "Generate..."
	@docker run --rm --name your-service-generate-running -v $(shell pwd):/go/src/github.com/your-name/your-service your-service-generate

@kasirajanss93
Copy link

It would be nice if you could add support to go mod

@glyn
Copy link

glyn commented Nov 8, 2018

We've decided to use counterfeiter (which does support Go modules) instead of mockery in a new go modules project in spite of the fact that we've been happily using mockery in non-module code. Some of mockery's features are missed, but at least counterfeiter works. We could potentially switch back to mockery if/when this issue is fixed.

@atombender
Copy link
Contributor Author

@evanphx?

@davisford
Copy link

Has there been a new release with PR #218? Doing standard install of mockery still has problem for me.

@atombender
Copy link
Contributor Author

@davisford It's merged. This project doesn't do releases or tags, unfortunately, but go get -u (or cloning + go install) should get you the latest one. If you still have problems, maybe you can create a new issue, and I'll take a look.

sbawaska pushed a commit to projectriff-archive/cnab-k8s-installer-base that referenced this issue Mar 21, 2019
* switch to counterfeiter for mock generation because of vektra/mockery#213
* fix some tests which flake due to non-deterministic order of ranging over maps
* update all the indirect requirements in go.mod which correspond to dependencies in riff Gopkg.lock
  to use the revision sha and run make to sanitise them
* strip out Apache license headers

Part of https://github.com/pivotal-cf/pfs/issues/44
Part of https://github.com/pivotal-cf/pfs/issues/45
sbawaska pushed a commit to projectriff-archive/cnab-k8s-installer-base that referenced this issue May 21, 2019
* switch to counterfeiter for mock generation because of vektra/mockery#213
* fix some tests which flake due to non-deterministic order of ranging over maps
* update all the indirect requirements in go.mod which correspond to dependencies in riff Gopkg.lock
  to use the revision sha and run make to sanitise them
* strip out Apache license headers

Part of pivotal/pfs#44
Part of pivotal/pfs#45
sbawaska pushed a commit to projectriff/k8s-manifest-scanner that referenced this issue Jul 16, 2019
* switch to counterfeiter for mock generation because of vektra/mockery#213
* fix some tests which flake due to non-deterministic order of ranging over maps
* update all the indirect requirements in go.mod which correspond to dependencies in riff Gopkg.lock
  to use the revision sha and run make to sanitise them
* strip out Apache license headers

Part of https://github.com/pivotal-cf/pfs/issues/44
Part of https://github.com/pivotal-cf/pfs/issues/45
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.

7 participants