Home >Backend Development >Golang >Why Does My Go Project Show 'Package XXX is not in GOROOT'?
"Package XXX is not in GOROOT" when Building a Go Project
Debugging the error "package project/game is not in GOROOT" requires understanding the concept of Go modules and project layout.
Go Modules and Project Structure:
In newer versions of Go (post 1.13), Go modules are used to manage package dependencies. A Go module is typically a directory containing a go.mod file and source code. The go.mod file declares the module's name, its dependencies, and where it is located in the filesystem.
Resolving the Issue:
Examine Build Command:
Verify the command that Goland is using to build the project. It should be similar to:
go build -o C:UsersusernameAppDataLocalTemp___go_build_project_server.exe project/server
This command should not specify the GOROOT flag.
Workflow with Nested Packages:
If your project has nested packages, such as "project/game/entity," you should follow these additional steps:
Import Packages in Subdirectories:
In the subdirectory's source code, import the package from the parent module using the syntax:
import "parent/submodule"
By following these steps, you can resolve the "package project/game is not in GOROOT" error and correctly build your Go project with nested packages.
The above is the detailed content of Why Does My Go Project Show 'Package XXX is not in GOROOT'?. For more information, please follow other related articles on the PHP Chinese website!