# 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)

**Code:** `cannot find package in any of GOROOT / GOPATH` · **Category:** Go · **Seen on:** Go

Go could not locate an imported package — it is not downloaded, the module is not initialised, or GOPATH mode is in effect.

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

1. `go mod init example.com/app && go mod tidy`
2. Unset `GO111MODULE` or set `on`
3. `go get github.com/pkg/errors`

## Detailed fix by platform

### Go

1. `go env GO111MODULE GOFLAGS GOPATH` shows the active mode

## How to diagnose

1. **Mode** — go.mod present?
2. **Env** — GO111MODULE?
3. **Path** — Import spelled right?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/go/cannot-find-package)
