I just updated to the new version of Go - Go version 1.16.2 Linux/amd64 and am getting an error when I build a Hello, World! example:
go: go.mod file not found in current directory or any parent directory; see 'go help modules'
Even when I follow the fix from that post it isn't working. I set these variables and then build again:
GO111MODULE=on GOPROXY=https://proxy.golang.org,direct
And the same problem unfortunately.
What is Go Module. A Module is a collection of Go packages stored in a file tree under $GOPATH/pkg folder with a go. mod file at its root. This file defines the module's path, which is also the import path used for your project, and its dependency requirements, which are the other modules needed for a successful build.
The go. mod file defines the module's module path, which is also the import path used for the root directory, and its dependency requirements, which are the other modules needed for a successful build. Each dependency requirement is written as a module path and a specific semantic version.
Open a command prompt and cd to your home directory. Create a greetings directory for your Go module source code. Start your module using the go mod init command. Run the go mod init command, giving it your module path -- here, use example.com/greetings .
mod module config file in your project's root directory. The file will contain the module and Go version information. The file stipulates the project's requirements and lists all the needed dependencies—it's like the package.
go: go.mod file not found in current directory or any parent directory; see 'go help modules' Go module is the official go dependency management library of go, which is officially recommended in version 1.13 Go module can organize all dependencies under a project (folder) into one go Mod file, in which the dependent version is written
It’s still possible to build packages in GOPATH mode by setting the GO111MODULE environment variable to off . You can also set GO111MODULE to auto to enable module-aware mode only when a go.mod file is present in the current directory or any parent directory.
The automatic fixes weren’t always desirable: if an imported package wasn’t provided by any required module, the go command would add a new dependency, possibly triggering upgrades of common dependencies. Even a misspelled import path would result in a (failed) network lookup.
Previously, when the go command found a problem with go.mod or go.sum like a missing require directive or a missing sum, it would attempt to fix the problem automatically. We received a lot of feedback that this behavior was surprising, especially for commands like go list that don’t normally have side effects.
Change this:
go env -w GO111MODULE=auto
to this:
go env -w GO111MODULE=off
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With