go module_error ai_generated true

package example.com/foo is not in GOROOT (/usr/local/go/src/example.com/foo)

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2025-04-02First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.16 active
1.17 active

Root Cause

Import path is incorrectly resolved to GOROOT's standard library instead of a module dependency.

generic

中文

导入路径被错误解析为GOROOT下的标准库,而不是模块依赖。

Workarounds

  1. 80% success 确保在模块目录内运行
    cd /path/to/module && go build
  2. 90% success 设置GO111MODULE=on
    export GO111MODULE=on
    go build

Dead Ends

Common approaches that don't work:

  1. 复制包到GOROOT目录 90% fail

    GOROOT不应被修改,且这不是正确做法。

  2. 设置GO111MODULE=off 70% fail

    禁用模块模式会导致其他依赖问题。