在将Go从1.14更新到1.17之后,我得到了这个错误:
main.go:10:2: no required module provides package github.com/gin-gonic/gin: \
go.mod file not found in current directory or any parent directory; \
see 'go help modules'我曾经可以用go get github.com/gin-gonic/gin来解决这个问题,但是现在这已经没有用了。有什么改变了吗?
发布于 2021-09-02 12:40:57
如果我有这样的文件,我可以重现它:
package hello
import _ "github.com/gin-gonic/gin"并运行以下命令:
go mod init hello
go build我的修复方法是运行以下命令:
go mod tidy发布于 2021-09-02 14:18:12
从Go 1.16开始,“无论go.mod文件是否存在于当前工作目录或父目录中,默认情况下都会启用模块感知模式。更准确地说,GO111MODULE环境变量现在默认为on。“
有关如何迁移的快速概述,请参阅Migrating to Go Modules博客文章,或参阅Tutorial: Create a Go Module了解更多详细信息。
https://stackoverflow.com/questions/69025385
复制相似问题