go 解决no required module provides package xxx: go.mod file not found in current directory or any parent directory; see 'go help modules'
2021-09-14 21:21
471 查看
背景
我覆盖升级安装了go的较新的版本。
现象
更新后,运行程序就报这个错
no required module provides package xxx: go.mod file not found in current directory or any parent directory; see 'go help modules'
解决
网上找的命令:
go env -w GO111MODULE=auto
解释一下命令:
GO111MODULE是 go modules 功能的开关,关于go modules本文不详述,这个涉及到go的一种很重要的管理机制,我们可以简单的理解为,在没有go modules机制时,go工程中对于第三方功能包的管理非常复杂,也非常专业,这就导致程序员在进行开发的时候,对于第三方功能包的管理很不方便,所以才有了go modules机制。这个机制的开关是通过GO111MODULE环境变量来配置的。
GO111MODULE=off,无模块支持,go命令行将不会支持module功能,寻找依赖包的方式将会沿用旧版本那种通过vendor目录或者GOPATH模式来查找。
GO111MODULE=on,模块支持,go命令行会使用modules,而一点也不会去GOPATH目录下查找。
GO111MODULE=auto,默认值,go命令行将会根据当前目录来决定是否启用module功能。这种情况下可以分为两种情形:
(1)当前目录在GOPATH/src之外且该目录包含go.mod文件,开启模块支持。
(2)当前文件在包含go.mod文件的目录下面。
相关文章推荐
- cloudera-scm-server启动时出现Caused by: java.io.FileNotFoundException: /var/lib/cloudera-scm-server/.keystore (No such file or directory)问题解决方法(图文详解)
- 解决FileNotFoundError: [Errno 2] No such file or directory: 'xxx.jpg'错误
- Xcode开发c++程序时,openssl/aes.h: No such file or directory(或者是file not found)怎么解决
- firewalld.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead
- 解决错误:NAND: could not create temp file for system NAND disk image: No such file or directory
- 真机调试出问题“Could not launch 'app name'”,No such file or directory 的bug解决
- XCode报错 error: failed to launch “XXX.app”-- No such file or directory (XXXXXX)解决方法
- git 出现The current branch is not configured for pull No value for key branch.master.merge found in configuration错误的解决办法
- clang: error: no such file or directory: '/Users/bigxin/Desktop/not file xxx
- modprobe: FATAL: Module xxx.ko not found in directory /lib/modules/$(uname -r)
- 解决MAC下PHP连接MYSQL错误Warning: mysql_connect(): No such file or directory in conn.php
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions异常原因及解决方法
- 解决MAC下PHP连接MYSQL错误Warning: mysql_connect(): No such file or directory in conn.php
- 解决The current branch is not configured for pull No value for key branch.master.merge found in config
- 运行docker容器时报standard_init_linux.go:195: exec user process caused "no such file or directory" 的解决方法
- 如何解决Could not launch app - No such file or directory
- 解决The current branch is not configured for pull No value for key branch.master.merge found in config
- 解决:According to TLD or attribute directive in tag file, attribute value does not accept any express。
- Linux启动MyCat报错:Could not write pid:No such file or directory 解决办法
- httpd: Could not open configuration file /xxx/conf/httpd.conf: No such file or directory