[Fix] go go mod file not found in current directory or any parent directory; see ‘go help modules’

The Error “go: go.mod file not found in current directory or any parent directory; see ‘go help modules'”, is an error that is invoked when you are working with Go and have recently updated your go-go version. Given below is the snippet of the error you might get:

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

I would like to share with you the steps I took to fix the “go: go.mod file not found in current directory or any parent directory; see ‘go help modules'”

Why “go go mod file not found in current directory or any parent directory; see ‘go help modules'” Error is Seen?

The error, “go: go.mod file not found in current directory or any parent directory; see ‘go help modules'” is seen because the GO111MODULE value is not set to “off”. When the GO111MODULE value is set to “off” it forces Go to behave the GOPATH way, even outside of GOPATH.

You can check your GO111MODULE value by running the following command: bash go env

A detailed solution of the error, “go: go.mod file not found in current directory or any parent directory; see ‘go help modules'” is given below:

How to fix “go go mod file not found in current directory or any parent directory; see ‘go help modules'” Error?

To fix the error, you will have to set the GO111MODULE value to “auto” to fix the error. You can set the value to auto by running the following command “go env -w GO111MODULE=auto”. Once value is set to auto using command “go env -w GO111MODULE=auto”, error go: go.mod file not found in current directory or any parent directory; see ‘go help modules’ will be fixed.

To fix the error, “go: go.mod file not found in current directory or any parent directory; see ‘go help modules'”, you will have to follow the steps mentioned below:

By default the value of your GO111MODULE will be turned off which is what causing the error in the first place. You can check this by running the below mentioned command:

go env

If it is not set to auto you will have to do so by following the below mentioned command :

go env -w GO111MODULE=auto

Then you can go to your work directory’s terminal and run the below mentioned command to confirm you are not getting any errors:

go mod init
go mod tidy

This should fix the error “go: go.mod file not found in current directory or any parent directory; see ‘go help modules'”.

Conclusion

To fix the error “go: go.mod file not found in current directory or any parent directory; see ‘go help modules'”, you will have to set the GO111MODULE value to auto to fix the error. You can set the value to auto by running the following command go env -w GO111MODULE=auto