go
module_error
ai_generated
true
package X is not in GOROOT (/usr/local/go/src/X)
ID: go/package-is-not-in-goroot
90%Fix Rate
85%Confidence
1Evidence
2024-03-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| go1.21 | active | — | — | — |
| go1.22 | active | — | — | — |
| go1.23 | active | — | — | — |
Root Cause
The Go toolchain cannot find a package because it is not installed in the standard library path (GOROOT) and not part of a module; often due to missing go.mod or GOPATH issues.
generic中文
Go 工具链找不到包,因为它不在标准库路径 (GOROOT) 中,也不属于某个模块;通常是由于缺少 go.mod 或 GOPATH 问题。
Official Documentation
https://go.dev/doc/code#GOPATHWorkarounds
-
95% success Initialize a module: `go mod init mymodule` in the project root, then run `go mod tidy`.
Initialize a module: `go mod init mymodule` in the project root, then run `go mod tidy`.
-
80% success If using GOPATH, ensure the package is under `$GOPATH/src/X` and set `GO111MODULE=off`.
If using GOPATH, ensure the package is under `$GOPATH/src/X` and set `GO111MODULE=off`.
中文步骤
Initialize a module: `go mod init mymodule` in the project root, then run `go mod tidy`.
If using GOPATH, ensure the package is under `$GOPATH/src/X` and set `GO111MODULE=off`.
Dead Ends
Common approaches that don't work:
-
98% fail
GOROOT must point to the Go installation, not the project; this breaks the toolchain.
-
85% fail
This is not standard practice and will be overwritten on Go updates; also breaks module isolation.