“package XXX is not in GOROOT” when building Golang project

和自甴很熟 提交于 2020-12-08 06:06:31

问题


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!


回答1:


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.




回答2:


To anyone who does want modules to work with GoLand after they have stopped doing so, make sure 'Enable Go modules integration' is checked in the Preferences as such:




回答3:


I faced the same issue. Mostly your packages must be having their seperate "go.mod" file. Delete those files and it should work!

Also, please use linux :P. You'll get better community support :)



来源:https://stackoverflow.com/questions/61845013/package-xxx-is-not-in-goroot-when-building-golang-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!