go: go.mod file not found in current directory or any parent directory; see ‘go help modules‘

Posted 猎人在吃肉

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了go: go.mod file not found in current directory or any parent directory; see ‘go help modules‘相关的知识,希望对你有一定的参考价值。

一、问题描述

执行 main.go 报如下错误

go: go.mod file not found in current directory or any parent directory; see 'go help modules'

二、解决办法

在项目目录下打开cmd窗口,根据需要选择执行下面的命令。

1)开启 go modules 功能,命令行输入

go env -w GO111MODULE=on

2)在该项目目录下,初始化Go moudle,运行下面命令

go mod init
或者
go mod init xxx               // xxx 代表 目录名称

以上是关于go: go.mod file not found in current directory or any parent directory; see ‘go help modules‘的主要内容,如果未能解决你的问题,请参考以下文章

go: go.mod file not found in current directory or any parent directory; see ‘go help modules‘

go.mod file not found in current directory or any parent directory; see ‘go help modules‘

go: go.mod file not found in current directory or any parent directory; see ‘go help modules‘

go: go.mod file not found in current directory or any parent directory; see ‘go help modules‘

解决go: go.mod file not found in current directory or any parent directory; see ‘go help modules‘

解决go: go.mod file not found in current directory or any parent directory; see ‘go help modules‘