This error often occurs when trying to build or run a Go project and encounters the following scenario:
The project is structured as follows:
src/ |--project |--game |--entity |--whatever.go |--game_stuff.go |--server
In recent versions of Go (post 1.13), setting environment variables like GOPATH and GOBIN is no longer necessary. Instead, the project should contain a go.mod file at its root, which denotes it as a Go module.
To resolve this issue, follow these steps:
For the sample project structure provided:
Create a go.mod file in the project root directory and include the following:
module github.com/myorg/myproject go 1.17 require ( github.com/myorg/gameutils v1.2.3 )
Remove or comment out obsolete environment variables:
# GOPATH=$HOME/go # Assuming previous GOPATH setting
The above is the detailed content of Why Am I Getting the 'package XXX is not in GOROOT' Error in My Go Project?. For more information, please follow other related articles on the PHP Chinese website!