[Go 报错] go: go.mod file not found in current directory or any parent directory

Build Error: go build -o c:\Users\13283\Desktop\godemo\__debug_bin3410376605.exe -gcflags all=-N -l .

go: go.mod file not found in current directory or any parent directory; see 'go help modules' (exit status 1)

原因分析:

go 的环境配置问题。与 golang 的包管理有关

处理方案:

如果你是 Windows 系统,快捷键 "Win+R",输入cmd,打开终端。输入:

复制代码
go env -w GO111MODULE=auto

解释:

GO111MODULE 是 Go 1.11 引入的新版模块管理方式。

GO111MODULE 环境变量用于开启或关闭 Go 语言中的模块支持,它有 off、on、auto 三个可选值,默认为 auto。

GO111MODULE=off

无模块支持,go 会从 $GOPATH 文件夹和 vendor 目录中寻找依赖项。

GO111MODULE=on

模块支持,go 忽略 $GOPATH 文件夹,只根据 go.mod 下载依赖。

GO111MODULE=auto

在 $GOPATH/src 外层且根目录有 go.mod 文件时,开启模块支持;否者无模块支持

相关推荐
uzong3 分钟前
研发工程师晋升背后的逻辑:一些背后的思考与行动指南
后端
追逐时光者38 分钟前
C# 中值类型和引用类型的主要区别是什么?
后端·.net
Victor3562 小时前
MongoDB(32)如何查看集合中的索引?
后端
Victor3562 小时前
MongoDB(33)什么是唯一索引?
后端
大鸡腿同学2 小时前
后端
IT_陈寒2 小时前
Vite 凭什么比 Webpack 快50%?揭秘闪电构建背后的黑科技
前端·人工智能·后端
颜酱2 小时前
Dijkstra 算法:从 BFS 到带权最短路径
javascript·后端·算法
aircrushin3 小时前
OpenClaw“养龙虾”现象的社会技术学分析
前端·后端
37手游后端团队3 小时前
全网最简单!从零开始,轻松把 openclaw 小龙虾装回家
人工智能·后端·openai
Apifox4 小时前
测试数据终于不用到处复制了,Apifox 自动化测试新增「共用测试数据」
前端·后端·测试