栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Go语言

【Go报错】go: go.mod file not found in current directory or any parent directory 错误解决

Go语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【Go报错】go: go.mod file not found in current directory or any parent directory 错误解决

场景:

安装好 liteide 之后创建了第一个 “hello world” 的golang 项目,却报了如下错误。


问题描述:

报错:

D:/golang/bin/go.exe build [C:/Users/dell/go/src/hello]
go: go.mod file not found in current directory or any parent directory; see 'go help modules'
错误: 进程退出代码 1.

原因分析:

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


解决方案:

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

go env -w GO111MODULE=auto

解释:

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

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

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

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

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


参考链接
  1. go.mod file not found in current directory or any parent directory; see ‘go help modules‘
  2. Go语言常用环境变量
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/965424.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号