"package XXX is not in GOROOT" when building Golang project

Michael Shum picture Michael Shum · May 17, 2020 · Viewed 72.5k times · Source

I have a weird issue that arose when I took a break from this project. Upon starting up Goland, I'm riddled with errors when trying to run my project.

The specific error, when building one of my packages, is: start.go: package project/game is not in GOROOT (C:\Go\src\project\game)

I have a folder structure as such under C:\Users\username

go
|-src
   |-project
        |-game
            |-entity
                 |-whatever.go
            |-game_stuff.go
        |-server

and my env vars are as such:

GOROOT=C:\Go 
GOPATH=C:\Users\ketchup\go 

for each of the modules (project/game/entity, project/game, project/server), I did a git mod init.

When building, Goland will try to run this:

C:\Go\bin\go.exe build -o C:\Users\ketchup\AppData\Local\Temp\___go_build_project_server.exe project/server

and return the error.

Can anyone help me with this issue? Kind of lost since Goland was working fine the last time I opened it. Also not even sure what direction to look at - I'm pretty new to Go and I'm not really sure what documentation to look at :\ Thank you everyone!

Answer

Michael Shum picture Michael Shum · May 18, 2020

A pretty dumb conclusion (mostly on my part) but my issue came from having done go mod init in each of the folders. after removing go.mod and go.dep from each of the folders I did go mod init in, I could build without issue (through terminal)

Also, my packages in GoLand were not being detected because I had Go Modules enabled in the Settings. I disabled it and GoLand was able to index the external packages and my own packages.