Go: cannot find package "github.com/pkg/errors" in any of: /usr/local/go/src/github.com/pkg/errors (from $GOROOT) /go/src/github.com/pkg/errors (from $GOPATH)
Go could not locate an imported package — it is not downloaded, the module is not initialised, or GOPATH mode is in effect.
cannot find package in any of:cannot find package "github.com/pkg/errors" in any ofpackage is not in GOROOTpackage is not in stdcannot find package in any of GOROOT GOPATH Meaning
In module mode run go mod init and go mod tidy (or go get pkg). The GOROOT/GOPATH wording means Go is running in legacy GOPATH mode (GO111MODULE=off or no go.mod). Ensure a go.mod exists in the project root and that GO111MODULE is not off.
Common causes
- No go.mod in the project
- GO111MODULE=off
- Dependency not downloaded
- Typo in the import path
- Vendor directory out of date
⚡ Quick fix
go mod init example.com/app && go mod tidy- Unset
GO111MODULEor seton go get github.com/pkg/errors
Detailed fix by platform
Go
go env GO111MODULE GOFLAGS GOPATHshows the active mode
How to diagnose
- Mode — go.mod present?
- Env — GO111MODULE?
- Path — Import spelled right?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- go: updates to go.mod needed Go: go: updates to go.mod needed; to update it: go mod tidy
- import cycle not allowed Go: package app/models imports app/utils imports app/models: import cycle not allowed
- invalid version: unknown revision Go: go: github.com/foo/bar@v1.2.3: invalid version: unknown revision v1.2.3
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026