Golang error: go.mod file not found in current directory

Today when I was compiling a Go program, I got the following error:

Error message "go: go.mod file not found in current directory or any parent directory; see 'go help modules'"

I checked the environment variables to see if the Go execution path is set.

$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOENV="/Users/user/Library/Application Support/go/env"

It appears that VS Cod was not able to find the compiler. I run the following command.

% go env -w GO111MODULE=auto

After that, I checked the environment variables again.

% go env
GO111MODULE="auto"

Now the program compiled just like normal.

Leave a Comment

Your email address will not be published. Required fields are marked *