VSCode: Could not import Golang package

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. (also check the updates at the end of the answer)

.  <- editor open here
| 
|_Folder
  | main.go
  | go.mod
  | go.sum
  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

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)