Go语言在VS code中报错go.mod file not found in current directory or any parent directory
# Go语言在VS code中报错go.mod file not found in current directory or any parent directory
# 问题
在VS code中编辑第一个 go 程序的时候,会报错
显示go: go.mod file not found in current directory or any parent directory; see 'go help modules'
如下图
但是程序在命令行中是可以正常编译的
# 解决方案
在cmd中输入go env
,可以看到第一项GO111MODULE是空的
此时便要修改它。在cmd中输入
go env -w GO111MODULE=auto
1
修改完成后,回到VS code中,报错就消失啦
在Github中编辑 (opens new window)
上次更新: 2024/04/21, 13:07:28