VSCode: Could not import Golang package

I encountered a similar problem, but the situation is slightly different. I encountered this problem in VSCode remote, and even the basic library like net/http cannot be imported. I found that it was because of some syntax errors in other files under the same package, such as undefined variables. When I solved these syntax errors and restarted VSCode, I found that the problem was solved.


This happens to me in a few specific situations. This is my troubleshooting process :

  1. Did you run go get github.com/gomodule/redigo/redis?

  2. Sometimes I have a similar issue when I open my editor in a root different than my project.

.  <- editor open here
| 
|_Folder
  | main.go
  1. Make sure your tools are up to date: run ctrl + shift + p, type Go and chose Install/Update tools.

  2. Try moving your project out of the GOPATH, and setting up go.mod for it.

  3. Restart the editor


I had a same sort of issue with a different package (on mac),

  1. Update the go tools - ctrl + shift + p or cmd + shift + p and update/install go tools
  2. Restart VScode

Issue solved