Validator: cannot find package "github.com/go-playground/validator/v10" in any of

Created on 15 Jan 2020  路  20Comments  路  Source: go-playground/validator

Package version eg. v8, v9:

v10

Issue, Question or Enhancement:

go get github.com/go-playground/validator/v10

give following error

package github.com/go-playground/validator/v10: cannot find package "github.com/go-playground/validator/v10" in any of:
        /usr/local/go/src/github.com/go-playground/validator/v10 (from $GOROOT)
        /go/src/github.com/go-playground/validator/v10 (from $GOPATH)

Code sample, to showcase or reproduce:

using golang docker latest

$ docker run -it --rm golang sh
$ go get github.com/go-playground/validator/v10
package github.com/go-playground/validator/v10: cannot find package "github.com/go-playground/validator/v10" in any of:
        /usr/local/go/src/github.com/go-playground/validator/v10 (from $GOROOT)
        /go/src/github.com/go-playground/validator/v10 (from $GOPATH)

Most helpful comment

Hi folks, I stumbled with this issue. In my case this is used by another library(gin) but I noticed there is no v10 directory, and since I read this v10 was used for a transition but not longer exists, maybe symlinking to the same project work, and in fact it worked.

And yes, I know it's too hacky and I don't really know the side effects.

I did:
$cd $GOPATH/src/github.com/go-playground/validator/ $ln -s . v10

All 20 comments

Having this issue on OSX as well.

having the same problem when trying to run go get -v github.com/gin-gonic/gin since this is the default validator ... running it in docker > fetching for debian:stretch

EDIT: was trying to update packages for an older project where i fixed the golang version to 1.10. updating to 1.11 seems to resolve this issue in my case (but lets see what else breaks)

Hey @faisalburhanudin @minism & @lmapii

There are a few questions I have, I believe that this is a Go Version & Go Modules mismatch issue for you.

  1. What version of Go are you running?
  2. Where are you running the go get command? eg. inside the GOPATH, outside
  3. Is your project using go modules?

FWIW I get the same error if I run this command:

  • In a project NOT using Go modules within the GOPATH
  • Not in the directory where the go.mod|sum files reside
  • Using a version of go which doesn't support Go Modules (haven't tested this but pretty sure it will error the same way given @lmapii's fix of update the Go Version)

The takeaway is that this command needs to be run on a go project that's using Go Modules where the go.* files reside using a version of Go that support go Modules eg. v1.11+

please let me know if this get's you past your issue :)

P.S. didn't know gin updated to using v10 by default, awesome 馃殌

@deankarn

I have the same issue, which I emailed you few days back.

This is my go version. go version go1.13.3 darwin/amd64

In a project NOT using Go modules within the GOPATH
Not in the directory where the go.mod|sum files reside
Using a version of go which doesn't support Go Modules (haven't tested this but pretty sure it will error the same way given @lmapii's fix of update the Go Version)

Your package breaks this go get gin command.

go get -u github.com/gin-gonic/gin

I just initialised my project with go mod init command. Your go get command working after that.

having the same problem when trying to run go get -v github.com/gin-gonic/gin since this is the default validator ... running it in docker > fetching for debian:stretch

EDIT: was trying to update packages for an older project where i fixed the golang version to 1.10. updating to 1.11 seems to resolve this issue in my case (but lets see what else breaks)

Any update for this? I am facing exactly the same issue when updating gin.

The reason that鈥檚 this isn鈥檛 working is really that go modules is a breaking change to the ecosystem and isn鈥檛 compatible with previous tooling.

unfortunately there鈥檚 not much I can do about that from this package. If gin changed the import path back to github.com/go-playground/validator and then changed the go mod file to import by tag instead eg. Go get github.com/go-playground/[email protected] that may be an option but for non go modules projects you鈥檇 lose versioning of this package and always be pulling the latest master.

The unfortunate reality is if you want to use a package like gin that has converted to using go modules one should really update their program to use go modules. The alternative is to keep using and older version of gin using some other dependency management.

To solve this I recommend:

  • updating to a version of go that supports go modules.
  • convert your program to use go modules.
  • move your package out of the GOPATH

Please let me know that this helps.

@Higan as mentioned in the EDIT for me updating my golang version did the trick ... it's really a pity that this module topic broke older golang projects (due to the fact that earlier versions of the language simply didn't allow to explicitly specify certain versions as dependencies).

these are the steps i'm using in my dockerfile:

FROM debian:stretch AS install

# some more steps here but won't list all of them

ENV GOLANG_VERSION 1.11

RUN wget -O go.tgz "https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz" && \
    tar -C /usr/local -xzf go.tgz && \
    rm go.tgz && \
    mkdir /go

ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH

RUN go version

RUN go get -v github.com/gin-gonic/gin

Had the same problem with golang:1.14.2-alpine3.11, added

RUN go mod init

to the dockerfile fixed the issue.

Hi @deankarn ,
I'm able to reproduce this issue on an official golang v:1.14.2 docker image.

Dockerfile:

FROM golang:1.14.2

# Path
ENV GOBIN=$GOPATH/bin
ENV PATH=$PATH:$GOBIN

RUN go get -u github.com/go-playground/validator/v10

CMD tail -f /dev/null

Build command: docker build -f ./Dockerfile .

Error:
Sending build context to Docker daemon 2.676GB Step 1/5 : FROM golang:1.14.2 as builder ---> 2421885b04da Step 2/5 : ENV GOBIN=$GOPATH/bin ---> Using cache ---> 529a68b0b64d Step 3/5 : ENV PATH=$PATH:$GOBIN ---> Using cache ---> 1ea739674f07 Step 4/5 : RUN go get -u github.com/go-playground/validator/v10 ---> Running in c3989c7297c5 package github.com/go-playground/validator/v10: cannot find package "github.com/go-playground/validator/v10" in any of: /usr/local/go/src/github.com/go-playground/validator/v10 (from $GOROOT) /go/src/github.com/go-playground/validator/v10 (from $GOPATH) The command '/bin/sh -c go get -u github.com/go-playground/validator/v10' returned a non-zero code: 1

Please advise,
Thanks!

@eldad87 have you tried the solution just above your post? Adding it just before (another RUN or in-line the existing one) your RUN go get should work.

Hi @Linzdigr ,
Unfortunately I can only confirm that the installation process was successful, everything else just broke.

RUN go mod init
go get github.com/go-playground/validator/v10
... 
Installations past those ^ lines broke.

Surgery was successful but the patient died.

@eldad87 you either have to write RUN docker command on each line or use && \ before each newline followed by another command.

Note that some persistent operation may not be accessible from a RUN operation to another as Docker commit a new image layer on each of them.

For those reasons, it is recommended to use the bash operator && between each command you want to execute.

For instance, RUN apt update && apt install -y...

Also note that any return code different from 0 will stop the command chain.

Hi folks, I stumbled with this issue. In my case this is used by another library(gin) but I noticed there is no v10 directory, and since I read this v10 was used for a transition but not longer exists, maybe symlinking to the same project work, and in fact it worked.

And yes, I know it's too hacky and I don't really know the side effects.

I did:
$cd $GOPATH/src/github.com/go-playground/validator/ $ln -s . v10

same problem here, @alexxsanchezm not work.

same problem here, @alexxsanchezm not work.

Hello, I can't ensure it's gonna work, but make sure your $GPATH var is properly set.

I fix it by running go mod init on the project.

so I think the issue can be closed, thank you

export PATH=$PATH:$(go env GOPATH)/bin this command solves the problem without the go mod init

i also meet this question, however i found the problem is that permission is wrong in $GOPATH, i solved it by follwing commands:

# cd $GOPATH/pkg/mod/github.com
# sudo rm -rf go-playgroud

and it works.

Was this page helpful?
0 / 5 - 0 ratings