Golang中无法找到github.com/Azure/go-autorest/autorest/adal/token.go的包如何解决
Golang中无法找到github.com/Azure/go-autorest/autorest/adal/token.go的包如何解决 大家好,
我正在开发一个使用“github.com/Azure/go-autorest/autorest/azure/auth”库的脚本。 启动代码后,我遇到了以下错误:
<User>@<host> az_ressourcen_version % go run main.go
../github.com/Azure/go-autorest/autorest/adal/token.go:40:2: cannot find package "github.com/golang-jwt/jwt/v4" in any of:
/usr/local/go/src/github.com/golang-jwt/jwt/v4 (from $GOROOT)
/Users/<User>/go/src/github.com/golang-jwt/jwt/v4 (from $GOPATH)
jwt 库已经安装,但在我的 go.mod 文件中,我发现了以下信息:
<User>@<host> jwt % cat go.mod
module github.com/golang-jwt/jwt/v5
go 1.18
require github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
运行 go mod tidy 并没有解决我的问题。
有人知道如何修复这个问题吗?
更多关于Golang中无法找到github.com/Azure/go-autorest/autorest/adal/token.go的包如何解决的实战教程也可以访问 https://www.itying.com/category-94-b0.html
Frank_Lohfeld:
nd package "github.com/golang-jwt/jwt/v4"
你的 GO111MODULE 环境变量是否设置为 "on"?当我将其设置为 off 时,也会遇到同样的错误。请使用 go env 命令检查。
func main() {
fmt.Println("hello world")
}
更多关于Golang中无法找到github.com/Azure/go-autorest/autorest/adal/token.go的包如何解决的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html
这个错误是因为 github.com/Azure/go-autorest/autorest/adal 包依赖的是 github.com/golang-jwt/jwt/v4,但你的项目中可能缺少这个依赖或者版本不匹配。
首先,确保你的 go.mod 文件中包含正确的依赖。运行以下命令来添加缺失的依赖:
go get github.com/golang-jwt/jwt/v4
如果问题仍然存在,可能是版本冲突。检查你的 go.mod 文件,确保没有其他依赖强制使用了不兼容的版本。你可以尝试更新所有依赖到最新版本:
go get -u ./...
或者,如果问题是由间接依赖引起的,可以尝试清理并重新下载所有依赖:
go mod tidy
go mod vendor
如果上述方法都不起作用,可能是缓存问题。清理 Go 模块缓存:
go clean -modcache
然后重新下载依赖:
go mod download
最后,运行你的程序:
go run main.go
如果问题仍然存在,检查 github.com/Azure/go-autorest/autorest/adal 的版本是否与 github.com/golang-jwt/jwt/v4 兼容。可能需要降级或升级其中一个包。例如,降级 github.com/Azure/go-autorest/autorest/adal:
go get github.com/Azure/go-autorest/autorest/adal@v0.9.22
或者,如果可能,升级到使用 jwt/v5 的版本。但请注意,github.com/Azure/go-autorest/autorest/adal 可能尚未支持 jwt/v5。

