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

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

Open
anthonyGuo opened this issue Oct 27, 2022 · 13 comments

Comments

@anthonyGuo
Copy link

anthonyGuo commented Oct 27, 2022

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

@shimron
Copy link

shimron commented Oct 31, 2022

did you fix it ? I have the same issue

@anthonyGuo
Copy link
Author

add this to go.sum

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

fixed.

@mieliespoor
Copy link

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?

@sgargan
Copy link

sgargan commented Jan 4, 2023

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

@domino14
Copy link

domino14 commented Feb 8, 2023

go mod tidy didn't work for me

@shimron
Copy link

shimron commented Mar 2, 2023

have a try with go mod vendor

@LandonTClipp
Copy link
Contributor

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.

@hsequeda
Copy link

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.

@PerMalmberg
Copy link

PerMalmberg commented Dec 4, 2023

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

@LandonTClipp
Copy link
Contributor

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

@j1cs
Copy link

j1cs commented Dec 27, 2023

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"

@apexskier
Copy link

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.

@yessaliyev
Copy link

yessaliyev commented Mar 20, 2024

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

thanks @j1cs

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

No branches or pull requests