This happens to me in a few specific situations. This is my troubleshooting process :
-
Did you run
go get github.com/gomodule/redigo/redis
? -
Sometimes I have a similar issue when I open my editor in a root different than my project. (also check the updates at the end of the answer)
. <- editor open here
|
|_Folder
| main.go
| go.mod
| go.sum
-
Make sure your tools are up to date: run
ctrl
+shift
+p
, typeGo
and choseInstall/Update tools
. -
Try moving your project out of the GOPATH, and setting up go.mod for it.
-
Restart the editor
Update for those with the issue “2”:
Go 1.18 has a new feature called workspace!
If you are opening your workspace in a root different than where your go mod files are, it is probably because you have multiple projects in the same folder. If that is the case, you can run:
go work init
go work use ./path-to-module ./path-to-module2
What it looks like:
. <- editor open here
| go.work
| app (folder)
| go.mod
| go.sum
| main.go
| client (folder)
| go.mod
| go.sum
| main.go