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

Used for two different module paths error in go mod tidy #37

Closed
turkenh opened this issue Jul 27, 2021 · 5 comments
Closed

Used for two different module paths error in go mod tidy #37

turkenh opened this issue Jul 27, 2021 · 5 comments

Comments

@turkenh
Copy link

turkenh commented Jul 27, 2021

I am trying to follow the steps in the migration guide however, I am getting the following error with go mod tidy:

go mod tidy
go: finding module for package github.com/golang-jwt/jwt/test
go: finding module for package github.com/golang-jwt/jwt/request
go: finding module for package github.com/golang-jwt/jwt
go: found github.com/golang-jwt/jwt in github.com/golang-jwt/jwt v3.2.1+incompatible
go: found github.com/golang-jwt/jwt/request in github.com/golang-jwt/jwt v3.2.1+incompatible
go: found github.com/golang-jwt/jwt/test in github.com/golang-jwt/jwt v3.2.1+incompatible
go: github.com/golang-jwt/jwt@v3.2.1+incompatible used for two different module paths (github.com/dgrijalva/jwt-go and github.com/golang-jwt/jwt)

Here is the PR: upbound/universal-crossplane#167

Any ideas how to fix that?

@oxisto
Copy link
Collaborator

oxisto commented Jul 27, 2021

I had a quick look into your PR and I fear that you are stuck in the middle for now. The replace route only works of you keep the original import path. Replacing the import path will not replace transitive imports.

My best guess would be to switch back to the old dgrijalva import path and use replace. Then once, your transitive dependency also switches to the new import path, remove the replace and switch the import path. Not really a good solution, but it is probably the "safest".

We probably should update the migration guide to reflect that you could run into this kind of problem with other transitive dependencies.

@jkawamoto
Copy link

jkawamoto commented Jul 27, 2021

Same here. I only run go mod edit and go mod tidy without editing any code but get this error:

$ go mod edit -replace github.com/dgrijalva/jwt-go=github.com/golang-jwt/jwt@v3.2.1+incompatible
$ go mod tidy
go: finding module for package github.com/golang-jwt/jwt/test
go: finding module for package github.com/golang-jwt/jwt
go: finding module for package github.com/golang-jwt/jwt/request
go: downloading github.com/golang-jwt/jwt v1.0.2
go: found github.com/golang-jwt/jwt in github.com/golang-jwt/jwt v3.2.1+incompatible
go: found github.com/golang-jwt/jwt/request in github.com/golang-jwt/jwt v3.2.1+incompatible
go: found github.com/golang-jwt/jwt/test in github.com/golang-jwt/jwt v3.2.1+incompatible
go: github.com/golang-jwt/jwt@v3.2.1+incompatible used for two different module paths (github.com/dgrijalva/jwt-go and github.com/golang-jwt/jwt)

I'm not sure why it tries to download v1.0.2 (go: downloading github.com/golang-jwt/jwt v1.0.2).

I also try to replace import paths in my code with gofmt -w -r '"github.com/dgrijalva/jwt-go" -> "github.com/golang-jwt/jwt-go"' . then get this error:

$ gofmt -w -r '"github.com/dgrijalva/jwt-go" -> "github.com/golang-jwt/jwt-go"' .
$ go mod download github.com/golang-jwt/jwt-go
go mod download: module github.com/golang-jwt/jwt-go: not a known dependency

go mod download github.com/golang-jwt/jwt-go@v3.2.1+incompatible doesn't return any errors but it looks like it doesn't work:

$ gofmt -w -r '"github.com/dgrijalva/jwt-go" -> "github.com/golang-jwt/jwt-go"' .
$ go mod download github.com/golang-jwt/jwt-go@v3.2.1+incompatible
$ go test ./... -v
main.go:25:2: no required module provides package github.com/golang-jwt/jwt-go; to add it:
        go get github.com/golang-jwt/jwt-go

I'm wondering if #30 could help. Btw, I'm using Go 1.16.6:

$ go version
go version go1.16.6 darwin/amd64

@jkawamoto
Copy link

I'm sorry I used the wrong repository name. This worked for me:

$ gofmt -w -r '"github.com/dgrijalva/jwt-go" -> "github.com/golang-jwt/jwt"' .
$ go get github.com/golang-jwt/jwt

@mfridman
Copy link
Member

I had a quick look into your PR and I fear that you are stuck in the middle for now. The replace route only works of you keep the original import path. Replacing the import path will not replace transitive imports.

My best guess would be to switch back to the old dgrijalva import path and use replace. Then once, your transitive dependency also switches to the new import path, remove the replace and switch the import path. Not really a good solution, but it is probably the "safest".

We probably should update the migration guide to reflect that you could run into this kind of problem with other transitive dependencies.

Ye, I don't know if there is a better solution here when using the replace directive. I believe this is related to golang/go#26904

I haven't been keeping a close eye on modules, but I think there is some work by @bcmills and the Go team to address such issues in 1.17 and/or 1.18

@mfridman
Copy link
Member

mfridman commented Aug 3, 2021

@turkenh @jkawamoto We just landed module support, so I'd suggest dropping the replace if you're having troubles with transitive dependencies and instead importing this package as "github.com/golang-jwt/jwt/v4".

Closing this issue. Feel free to continue commenting and/or create a new issue.

@mfridman mfridman closed this as completed Aug 3, 2021
git-hulk pushed a commit to apache/kvrocks that referenced this issue May 19, 2023
What's changed and what's your intention?

- And more specifically, I want to use bzpop<max|min|null>, <z|s>intercard, zmpop go APIs to write some go-unit tests for supporting more commands from `zset` or `set` in `kvrocks`. These commands from redis(version >= 6.2) are not implemented in this project.

- Due to redis/go-redis#2560 (comment), we should use `replace` in `go.mod` or change `"github.com/go-redis/redis/v9"` from import-blocks in go files.
The latter is more similar to contribsys/faktory@4454c4a and I prefer to try this based on golang-jwt/jwt#37 (comment).
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

4 participants