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

Open
atombender opened this Issue Aug 28, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@atombender
Contributor

atombender commented Aug 28, 2018

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/pgx@v3.1.0+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

This comment has been minimized.

Show comment
Hide comment
@atombender

atombender Aug 29, 2018

Contributor

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

Contributor

atombender commented Aug 29, 2018

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

@mjlangan

This comment has been minimized.

Show comment
Hide comment
@mjlangan

mjlangan 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/logrus@v1.0.6/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.

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/logrus@v1.0.6/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment