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 :
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.
. <- editor open here
|
|_Folder
| main.go
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
I had a same sort of issue with a different package (on mac),
- Update the go tools -
ctrl
+shift
+p
orcmd
+shift
+p
and update/install go tools - Restart VScode
Issue solved