Home >Backend Development >Golang >Why Can't My Go Build Find go.mod?
Unable to Locate go.mod File: Solving the "go.mod File Not Found" Error
You encounter an error message while building a Go program, stating that the "go.mod" file was not found in the current or parent directories. This is a common error when migrating to newer versions of Go due to the introduction of Go modules.
Go modules provide dependency management for Go projects and require a "go.mod" file at the root of the project to specify dependencies. If your project lacks this file, you will encounter the error message.
While setting the GO111MODULE and GOPROXY environment variables is a common fix, it does not resolve the issue in this case. The proper solution is to explicitly disable Go modules by setting the GO111MODULE environment variable to "off."
Solution:
Edit the command line to disable Go modules:
go env -w GO111MODULE=off
Rebuilding your project after setting this variable should resolve the "go.mod" file not found error.
The above is the detailed content of Why Can't My Go Build Find go.mod?. For more information, please follow other related articles on the PHP Chinese website!