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

mockgen: "package is not in GOROOT" when generating a mock outside of a module #480

zkuldeep opened this issue Sep 21, 2020 · 3 comments


Copy link

@zkuldeep zkuldeep commented Sep 21, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.6 darwin/amd64

Does this issue reproduce with the latest release?

Nothing as such

What operating system and processor architecture are you using (go env)?


go env Output
$ go env

What did you do?

Trying to generate mock for the provided interface 'CorHandler' in package 'designpattern'

for the given code:
`package designpattern

import "context"

// chain of responsibility handler
//go:generate mockgen -destination=mocks/mock_corhandler.go -package=mocks . CorHandler
type CorHandler interface {

// responsibility of current handler
Execute(context.Context, ...interface{}) error


command tried:
mockgen -destination=mocks/mock_corhandler.go -package=mocks internal/service/designpattern CorHandler

also: $pwd

What did you expect to see?

Something like mocks generated.

What did you see instead?

prog.go:14:2: package internal/service/designpattern is not in GOROOT (/usr/local/Cellar/go/1.14.6/libexec/src/internal/service/designpattern)
prog.go:12:2: cannot find module providing package working directory is not part of a module
prog.go:14:2: package internal/service/designpattern is not in GOROOT (/usr/local/Cellar/go/1.14.6/libexec/src/internal/service/designpattern)
2020/09/21 12:09:11 Loading input failed: exit status 1

Copy link

@bcmills bcmills commented Sep 22, 2020

Import paths without dots are in general reserved for the standard library (see golang/go#32819).

@bcmills bcmills transferred this issue from golang/go Sep 22, 2020
@bcmills bcmills changed the title package is not in GOROOT when trying for mockgen mockgen: "package is not in GOROOT" when generating a mock outside of a module Sep 22, 2020
Copy link

@codyoss codyoss commented Sep 22, 2020

Please use the full import path. Something like:

Copy link

@zkuldeep zkuldeep commented Sep 23, 2020

Thanks it resolved using fully qualified path. @codyoss & @bcmills

@zkuldeep zkuldeep closed this Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants