mockery icon indicating copy to clipboard operation
mockery copied to clipboard

mockery Error parsing file could not import golang.org/x/sync/semaphore (invalid package name: \"\")

Open anthonyGuo opened this issue 1 year ago • 14 comments

golang version go1.17.6 linux/amd64 mockery dry-run=false version=v2.9.4

go.mod require golang.org/x/sync v0.1.0

go mod download

go.sum 
      golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
      golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
      golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

log.go import ( "golang.org/x/sync/semaphore" )

mockery --all --inpackage --keeptree --output /root/baisheng/

27 Oct 22 07:32 UTC INF Starting mockery dry-run=false version=v2.9.4 27 Oct 22 07:32 UTC INF Walking dry-run=false version=v2.9.4 27 Oct 22 07:33 UTC ERR Error parsing file error="/root/baisheng/ git/ log.go:11:2: could not import golang.org/x/sync/semaphore (invalid package name: \" \")" dry-run=false version=v2.9.4

anthonyGuo avatar Oct 27 '22 07:10 anthonyGuo

did you fix it ? I have the same issue

shimron avatar Oct 31 '22 07:10 shimron

add this to go.sum

golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=

fixed.

anthonyGuo avatar Oct 31 '22 07:10 anthonyGuo

Seeing the same with aws sdk

Error parsing file error="/src/aws/ecs.go:9:2: could not import github.com/aws/aws-sdk-go/aws (invalid package name: \"\")" dry-run=false version=v2.14.1

go.sum:

github.com/aws/aws-sdk-go v1.44.126 h1:7HQJw2DNiwpxqMe2H7odGNT2rhO4SRrUe5/8dYXl0Jk=
github.com/aws/aws-sdk-go v1.44.126/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=

Any ideas how to fix this?

mieliespoor avatar Nov 04 '22 13:11 mieliespoor

this is super frustrating, but is often solved by running a go mod tidy

sgargan avatar Jan 04 '23 16:01 sgargan

go mod tidy didn't work for me

domino14 avatar Feb 08 '23 21:02 domino14

have a try with go mod vendor

shimron avatar Mar 02 '23 05:03 shimron

When running into this issue, please try using one of the binary distributions of mockery. A lot of these issues happen because of dependency issues in your go module, which is why go install is not recommended.

LandonTClipp avatar Mar 02 '23 17:03 LandonTClipp

I get this error with v2.26.1 using docker version, I solved it by running the same command with the binary version after run go mod download.

hsequeda avatar Oct 18 '23 17:10 hsequeda

Running go get on the module that, based on the error message, doesn't have a package name solved it for us.

Example: go get github.com/username/repo-name

PerMalmberg avatar Dec 04 '23 15:12 PerMalmberg

If others could confirm if that solution above works, I'll add it to the FAQ ^

LandonTClipp avatar Dec 05 '23 16:12 LandonTClipp

using -v "${GOPATH:-$HOME/go}/pkg/mod:/go/pkg/mod" worked for me:

docker run --rm \
    -v "${PWD}:/src" \
    -v "${PWD}/scripts/mockery.yaml:/mockery.yaml" \
    -v "${GOPATH:-$HOME/go}/pkg/mod:/go/pkg/mod" \
    -w /src \
    --user "$(id -u):$(id -g)" \
    vektra/mockery \
    --config="/mockery.yaml"

j1cs avatar Dec 27 '23 02:12 j1cs

go get and go mod tidy did not work for me. I hit this when my effective $GOPATH being used by my container had go 1.20 files in it and I was running in a go 1.21 context. (I'm running within a more complex docker abstraction). I was able to fix by passing in the proper versioned go path.

apexskier avatar Feb 22 '24 22:02 apexskier

-v "${GOPATH:-$HOME/go}/pkg/mod:/go/pkg/mod"

thanks @j1cs

yessaliyev avatar Mar 20 '24 06:03 yessaliyev