go mod tidy "all" matched no packages [duplicate]
Asked Answered
L

1

10

I've created a go module using this:

go mod init rtws
vim main.go # pasted a bunch of code from an example
go mod tidy

Both of these files import "github.com/gorilla/websocket", so when I used tidy I expected that it would download that dependency, but instead I got the following warning:

go: warning: "all" matched no packages

And subsequently trying to run it complained that the dependency did not exist.
What does this error mean?

EDIT: when searching, the most relevant thing I found was this other question on SO. A lot of people had this warning come up when running other commands but their solutions didn't work for this particular situation.

Lucerne answered 3/6, 2022 at 16:14 Comment(0)
L
5

I've found out what caused the issue while I was writing the question. At the top of the code that I pasted were the following lines:

//go:build ignore
// +build ignore

So, apparently this warning means there were no files in the module. The effect of the above lines tells go's build system to ignore that file, so go mod tidy behaved in the same way it would have if that file didn't exist.

Removing these allowed go mod tidy to do what I originally expected it to. Being new to golang this feature was not on the top of things I would have considered.

Lucerne answered 3/6, 2022 at 16:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.