当前位置:网站首页>【GO】go mod模式, package 12import/add is not in GOROOT
【GO】go mod模式, package 12import/add is not in GOROOT
2022-06-22 21:24:00 【weixin_43224306】
编译或run go工程时报该错,首先查看环境变量 go env 看GO111MODULE是什么状态。
分为两种情况处理
1,项目是mod模式
a) 如果GO111MODULE=on,则看看工程下面是否有go.mod文件,如果没有则go mod init一下
完事后 go mod tidy即可;
b) 如果GO111MODULE=on,且有go.mod,则直接go mod tidy;
c) 如果GO111MODULE=off,则开启mod模式 export GO111MODULE="on",然后继续走a)
d) 还有一种情况,本地go mod项目如果想手动传到linux上进行编译运行,若直接把go.mod文件直接传上去,则也会报这个错,正确的做法是在Linux目录下新创建该项目并执行go mod init ,然后把本地工程所有文件包括go.mod传上去再build,这时候就正常了哦
2,项目未开启mod模式
此时默认从$GOPATH下扫描,如果是在linux下编译或运行,则关闭GO111MODULE:
export GO111MODULE="off"
source /etc/profile
关闭后可go env再查一查是否生效;
如果是在goland下,则去掉该按钮-->ok -->鼠标空白处点点即可正常:

边栏推荐
- Fibonacci sequence set
- OJ daily practice - word length
- Is it difficult to turn weak current into professional network worker? Huawei pre-sales engineers share their own experience
- js----SVG转PNG
- 反向代理HAProxy
- Uniapp modifies array properties, and the view is not updated
- RedisTemplate使用遇到\x00的问题
- Reverse proxy haproxy
- 'dare not doubt the code, but have to doubt the code 'a network request timeout analysis
- Php7.3 error undefined function simplexml_ load_ string()
猜你喜欢

OJ每日一练——过滤多余的空格

Spark RDD Programming Guide(2.4.3)

考过HCIP依然转行失败,职业网工最看重的到底是什么

KunlunDB查询优化(二)Project和Filter下推

Is it difficult to turn weak current into professional network worker? Huawei pre-sales engineers share their own experience

Digital data depth | about software self-control, source code left, no code right

swagger2 使用方法

LeakCanary 源码详解(2)

昆仑分布式数据库Sequence功能及其实现机制

别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
随机推荐
14. 最长公共前缀
Programmers' choice of taking private jobs and part-time jobs
OJ每日一练——过滤多余的空格
OJ daily practice - filter extra spaces
Thead Safety心得体会
What does password security mean? What are the password security standard clauses in the ISO 2.0 policy?
os.Args[1:]中命令行参数为空时,不执行内部语句
剑指 Offer 05. 替换空格
js图片分辨率压缩
[kubernetes series] overview of kubernetes
OJ daily practice - Verifying substring
KunlunDB备份和恢复
在Word中自定义多级列表样式
DCC888 :SSA (static single assignment form)
China Mobile's mobile phone users grow slowly, but strive for high profit 5g package users
[arm] it is reported that horizontal display is set for LVDS screen of rk3568 development board
如何使用enum数据类型
OJ每日一练——单词的长度
swagger2 使用方法
tp5.1上传excel文件并读取其内容