mockery icon indicating copy to clipboard operation
mockery copied to clipboard

Running under go 1.18 throws 'package without types' error

Open pantsmann opened this issue 2 years ago • 3 comments

Description

go generate runs mockery --name .* When I ran this under go 1.17 there are no problems. After upgrading to go 1.18 I get an error: internal error: package "privaterepo/pkgone" without types was imported from "privaterepo/pkgtwo"

Version

mockery --version outputs: 07 Jun 22 18:48 MDT INF Starting mockery dry-run=false version=v0.0.0-dev v0.0.0-dev

I installed mockery_2.13.0-beta.1_Darwin_x86_64.tar.gz

Steps to Reproduce

Explained above. Note: I kept go 1.17 on my machine and running go1.17 generate has no problem.

Expected Behavior

mocks to be created

Actual Behavior

Got an error. See description

pantsmann avatar Jun 08 '22 00:06 pantsmann

Hi, can you provide a reproducer?

LandonTClipp avatar Jun 13 '22 19:06 LandonTClipp

We had the same issue using Go 1.18.2, but after upgrading mockery to v2.13.0, the errors went away.

bandesz avatar Jun 14 '22 10:06 bandesz

I was seeing this error with an older version as well but it stopped on update. I am getting invalid mocks generated now (imports "github.com/nats-io/") but I think it is probably due to weirdness of my interface.

import "github.com/nats-io/nats.go"

type Msg = nats.Msg
type MsgHandler = nats.MsgHandler
type Subscription = nats.Subscription

// Connection provides an interface over basic *nats.Conn methods that we need to interact with the broker
type Connection interface {
	// QueueSubscribe subscribes to a NATS subject, equivalent to default Subscribe if queuegroup not supplied.
	QueueSubscribe(string, string, MsgHandler) (*Subscription, error)
	// PublishMsg sends the provided NATS message to the broker.
	PublishMsg(*Msg) error
	// Drain will end all active subscription interest and attempt to wait for in-flight messages to process before closing.
	Drain() error
}

AlexCuse avatar Jun 18 '22 12:06 AlexCuse

This happens to me since I updated to go1.20 It happens with all mockery-versions, from v2.16.0 to v2.20.2

maja42 avatar Feb 22 '23 10:02 maja42

Having the same problem with go 1.20.1. Created a simple repo for reproduction https://github.com/jonmol/mockery-test

jonmol avatar Mar 22 '23 09:03 jonmol

I ran your reproducer and was not able to get the same error:

$ go generate generate.go
22 Mar 23 10:16 CDT INF Starting mockery dry-run=false version=v2.20.0
22 Mar 23 10:16 CDT INF Using config:  dry-run=false version=v2.20.0
22 Mar 23 10:16 CDT INF Walking dry-run=false version=v2.20.0
22 Mar 23 10:16 CDT INF Generating mock dry-run=false interface=IFoo qualified-name=github.com/jonmol/mockery-test version=v2.20.0

This means that it's almost guaranteed to be an environment issue. Please ensure you run go mod tidy on all your repos you're operating on, and also ensure that your entire local golang package cache has been wiped.

LandonTClipp avatar Mar 22 '23 15:03 LandonTClipp

go clean -modcache fixed it, thanks for the pointer @LandonTClipp

jonmol avatar Mar 24 '23 09:03 jonmol

See FAQ: https://vektra.github.io/mockery/v2.35/notes/#internal-error-package-without-types-was-imported

guettli avatar Oct 10 '23 09:10 guettli