当前位置:网站首页>【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 -->鼠标空白处点点即可正常:

边栏推荐
猜你喜欢

别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!

Future alternatives to IPv4! Read the advantages, features and address types of IPv6

Redis缓存

口令安全是什么意思?等保2.0政策中口令安全标准条款有哪些?

IPV4的未来替代品!一文读懂IPV6的优势特点和地址类型

wallys/WiFi6 MiniPCIe Module 2T2R 2 × 2.4GHz 2x5GHz

Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading

弱电转职业网工难不难?华为售前工程师分享亲身经历

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

如何使用enum数据类型
随机推荐
多种方案实现图片的懒加载
优化——线性规划
js图片分辨率压缩
事物系统的几种异常场景
tp5.1解决跨域
Sword finger offer 07 Rebuild binary tree
程序员接私活兼职选择
13. Roman numeral to integer
LeakCanary 源码详解(2)
c# sqlsugar,hisql,freesql orm框架全方位性能测试对比 sqlserver 性能测试
Asynchronous FIFO
Digital data depth | about software self-control, source code left, no code right
SOA Service Oriented Architecture
企业数字化不是各自发展,而是全面SaaS化推进
swagger2 使用方法
Uniapp modifies array properties, and the view is not updated
Redistemplate encountered problems with \x00
js----SVG转PNG
Sword finger offer 11 Minimum number of rotation array
Web Caching Technology