Go: Cannot Find Main Module; See 'Go Help Modules'

Go: Cannot Find Main Module; See 'Go Help Modules'

I recently started using Go. I installed go's extension on vscode and I can use some commands like go run and go build but when I run go test I get the following error:

go: cannot find main module; see 'go help modules'

although I have a *_test.go file.

When I run go help modules, I get the following output:

Modules are how Go manages dependencies.

A module is a collection of packages that are released, versioned, and
distributed together. Modules may be downloaded directly from version control
repositories or from module proxy servers.

For a series of tutorials on modules, see


For a detailed reference on modules, see 

By default, the go command may download modules from 
It may authenticate modules using the checksum database at
 Both services are operated by the Go team at Google.
The privacy policies for these services are available at
 and 
respectively.

The go command's download behavior may be configured using GOPROXY, GOSUMDB,
GOPRIVATE, and other environment variables. See 'go help environment'
and  for more information.
1

1 Answer

You have to initialize the project before you can run test:

go mod init puppy
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.