Compilation changes in Go 1.16? "go build" throws error

I have a simple application, one single main.go file. Previously, I would simply run go build and get a binary with the name of the directory, which is great. After updating to Go 1.16 release, which came out today, I now get this message:

go: cannot find main module, but found .git/config in /home/rjzak/go/src/myproj
	to create a module there, run:
	cd .. && go mod init

I’m not using modules with this project (it’s not a project really, just a set of simple tools that I converted from Python to Go, since it’s easier to manage, in my opinion). And GO111MODULE=on is not set, which I checked since Issue 31997 has a similar issue with that being a proposed fix. I also didn’t see anything about changes which would affect my usage of go build in the release notes.

Thoughts? Am I not doing things the “Go way”? If not, I’m happy to learn that the ideal mechanism is for small applications.


Go 1.16 Release Notes

Modules

Module-aware mode is enabled by default, regardless of whether a go.mod file is present in the current working directory or a parent directory. More precisely, the GO111MODULE environment variable now defaults to on. To switch to the previous behavior, set GO111MODULE to auto.

What is your output from the go env GO111MODULE command?

Thank you, I must have missed that.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.