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

边栏推荐
猜你喜欢

KunlunDB查询优化(三)排序下推

Tp5.1 upload excel file and read its contents

KunlunDB 查询优化(一)

flutter外包,承接flutter项目

SourceTree版本管理常用操作

SOA Service Oriented Architecture

昆仑分布式数据库独特的变量读写功能介绍

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

【STM32技巧】使用STM32 HAL库的硬件I2C驱动RX8025T实时时钟芯片

c# sqlsugar,hisql,freesql orm框架全方位性能测试对比 sqlserver 性能测试
随机推荐
mysql主从同步及其分库分表基本流程
SqlServer 复制表的自增属性
Array and string offset access syntax with curly braces is no longer support
IPV4的未来替代品!一文读懂IPV6的优势特点和地址类型
Flutter outsourcing, undertaking flutter project
Enjoy high-performance computing! Here comes the Tianyi cloud HPC solution
How to use swagger2
Redistemplate encountered problems with \x00
程序员接私活兼职选择
在Word中自定义多级列表样式
Canvas generate Poster
双重跨域:Access-Allow-Origin header contains multiple values“*, *”,but only one is allowed
Longest word in output string
13. 罗马数字转整数
os.Args[1:]中命令行参数为空时,不执行内部语句
2. interface (calculator)
Dml:data manipulation language
Optimization - linear programming
OJ daily practice - word length
web缓存技术