Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"package XXX is not in GOROOT" when building a Go project

Tags:

go

goland

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!

like image 972
Michael Shum Avatar asked May 16 '20 23:05

Michael Shum


People also ask

How do I install packages in go?

To install a package using go get follow the following steps: Step 1: Make sure to check whether the Golang is installed on your system by checking the version of Go. Step 2: Set the GOPATH by using the following command. Step 3: Now, set the PATH variable with the help of the following command.

How are packages used in go?

Go programs are organized into packages. A package is a collection of source files in the same directory that are compiled together. Functions, types, variables, and constants defined in one source file are visible to all other source files within the same package. A repository contains one or more modules.

What is the difference between Go module and package?

In Go, a package is a directory of .go files, and packages form the basic building blocks of a Go program. Using packages, you organize your code into reusable units. A module, on the other hand, is a collection of Go packages, with dependencies and versioning built-in.


1 Answers

You may have GO111MODULE set "on", which will be on the go mod. Turning off the GO111MODULE may resolve this problem.

go env -w GO111MODULE=off 
like image 154
daniel nie Avatar answered Sep 21 '22 23:09

daniel nie