VS Code BrokenImport error doesn't disappear golang

Issue

I have this irritating error message that doesn’t go away even though go runs the script successfully. I have already updated go tools. I checked out directories that are specified in this error message and actually it turns out that there are no package files here for downloaded modules, but they downloaded under $GOPATH/pkg directory. What should I do in order to get rid of this?

enter image description here

Solution

You need to open from a directory with go.mod file (module root) or a subdirectory of the main module. If you cannot (e.g. because you have to work with multiple modules), you will need to opt in to use the experimental mode with "gopls": { "build.experimentalWorkspaceModule": true } setting. This is a known limitation of the Go language server currently.
Answer by Hana

Answered By – Yuriy Kirel

Answer Checked By – Jay B. (GoLangFix Admin)

Leave a Reply

Your email address will not be published.