[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 文件时,开启模块支持;否者无模块支持

相关推荐
小巧的砖头8 小时前
C#会重蹈覆辙吗?系列之2:反射及元数据的性能问题
开发语言·前端·c#
梨子同志8 小时前
Spring Boot
后端
凯瑟琳.奥古斯特8 小时前
力扣1009补码解法C++实现
开发语言·c++·算法·leetcode·职场和发展
Fanta丶9 小时前
4.Activiti流程定义部署
后端
2601_963645929 小时前
【2026最新】MATLAB教程(附安装包,非常详细)
开发语言·matlab·信息可视化
闲猫10 小时前
Python 虚拟环境 virtualenv & uvicorn 服务搭建 & FAstAPI 使用
开发语言·python
Yeats_Liao10 小时前
18:JavaBean简介及其在表单处理与DAO设计模式中的应用-Java Web
java·后端·架构
梨子同志10 小时前
Docker
后端
woxiangkaile10 小时前
kernel6.1 新增驱动
后端
三月不知肉味y10 小时前
2026-07-05-JAVA面试场景题训练
java·开发语言·面试