Reputation: 742
I've created a new Go project and am trying to use VSCode. I have a go.mod
in the parent directory with the following:
module main
go 1.19
I created the project with Bazel and Gazelle, and can successfully build and run a simple "hello world" in my Terminal that imports from subdirectories in the project using the command bazel run //src/server:main
.
However, VSCode doesnt seem to understand any of this. I have Bazel and Go plugins installed. My VSCode gives me an import error that says
could not import src/server/models (no required module provides package "src/server/models")
And when i save my changes, VSCode tries to auto-compile and the IDE "Output" gives me the following error
/Project/path/.../src/server/main.go:6:2 package src/server/models is not in GOROOT (/opt/homebrew/Cellar/go/1.19.4/libexec/src/src/server/models)
Why in the world is it trying to use GOROOT? And why is it not working with the Bazel infrastructure?
Upvotes: 0
Views: 159
Reputation: 742
No idea how this happened but things are working now.
project
| WORKSPACE
| BUILD
| src
| go.mod (module src go 1.19)
| BUILD (# gazelle:prefix src) <-- this is the only line in this file
| server
| main.go <-- imports here finally fixed
| BUILD
| models
| BUILD
| models.go
Upvotes: 1