go module_error ai_generated true

package X is not in GOROOT (/usr/local/go/src/X)

ID: go/package-is-not-in-goroot

Also available as: JSON · Markdown · 中文
90%Fix Rate
85%Confidence
1Evidence
2024-03-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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#GOPATH

Workarounds

  1. 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`.
  2. 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`.

中文步骤

  1. Initialize a module: `go mod init mymodule` in the project root, then run `go mod tidy`.
  2. If using GOPATH, ensure the package is under `$GOPATH/src/X` and set `GO111MODULE=off`.

Dead Ends

Common approaches that don't work:

  1. 98% fail

    GOROOT must point to the Go installation, not the project; this breaks the toolchain.

  2. 85% fail

    This is not standard practice and will be overwritten on Go updates; also breaks module isolation.