go

"no required module provides package .out" error when running go test -coverprofile


I'm trying to generate a code coverage report for my Go project using the following command:

go test -coverprofile=coverage.out ./...

However, I get the following error:

no required module provides package .out; to add it:
        go get .out

Go: "no required module provides package .out" error when running go test -coverprofile

What I’ve Tried: Verified that the command syntax is correct and there are no extra spaces.

Ran go mod tidy to ensure all dependencies are correctly installed.

Restarted the terminal and made sure I am in the correct directory.

Ran the command for a single package:

go test -coverprofile=coverage.out .

This works for the current package, but the error persists when running on all packages with ./...

Tried specifying the full path for coverage.out, but it didn’t help.

How can I fix this error and generate a proper test coverage report for all packages in my project?

Ran go mod tidy to ensure all dependencies are correctly installed.

Restarted the terminal and made sure I am in the correct directory.

Ran the command for a single package:

go test -coverprofile=coverage.out .

This works for the current package, but the error persists when running on all packages with ./...

Tried specifying the full path for coverage.out, but it didn’t help.

Development Environment:
OS: Windows 10
Go version: 1.23.1
The module system (go.mod) is set up correctly, and dependencies are installed.


Solution

  • Since I’m using PowerShell, I needed to add quotes around the -coverprofile argument to prevent PowerShell from misinterpreting the command.