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

相关推荐
我能坚持多久3 分钟前
D20—C语言文件操作详解:从基础到高级应用
c语言·开发语言
橘子师兄20 分钟前
C++AI大模型接入SDK—ChatSDK封装
开发语言·c++·人工智能·后端
@ chen28 分钟前
Spring事务 核心知识
java·后端·spring
上天_去_做颗惺星 EVE_BLUE34 分钟前
Docker高效使用指南:从基础到实战模板
开发语言·ubuntu·docker·容器·mac·虚拟环境
2401_8576835435 分钟前
C++中的原型模式
开发语言·c++·算法
s1hiyu1 小时前
C++动态链接库开发
开发语言·c++·算法
(❁´◡`❁)Jimmy(❁´◡`❁)1 小时前
CF2188 C. Restricted Sorting
c语言·开发语言·算法
星火开发设计1 小时前
C++ 预处理指令:#include、#define 与条件编译
java·开发语言·c++·学习·算法·知识
许泽宇的技术分享1 小时前
第 1 章:认识 Claude Code
开发语言·人工智能·python
AIFQuant1 小时前
如何利用免费股票 API 构建量化交易策略:实战分享
开发语言·python·websocket·金融·restful