Home > OS >  VS Code BrokenImport error doesn't disappear golang
VS Code BrokenImport error doesn't disappear golang

Time:01-12

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

CodePudding user response:

Everything resolved once I opened folder with go.mod file in new vs code window, but it's inconvenient to do so since I want to manage my whole project. I guess something is still wrong down here.

CodePudding user response:

By default all our packages are downloaded into $GOPATH/pkg directory.

The issue that you are facing is happened due to sync issue in VSCode. Sometimes VSCode takes few second for sync meanwhile it will show an error.

You can get rid of with this issue by restarting the VSCode but make sure you have followed official docs Golang for VSCode.

  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 VSCode editor

Make sure after go get package_name you should press ctrl s though if you have turned on autosave. After 1 or 2 second popup will occur down right side saying changes are being saved and error will move away.

This is why when you opened code in new window error is gone.

  •  Tags:  
  • Related