Fix Go Error: "cannot find package" / "cannot find module providing package" (2026)

Go error: "cannot find package" / "cannot find module providing package"

The immediate fix depends on your project mode. In a module project (one with a go.mod file), run:

go get <import-path>

In an old GOPATH-style tree, place the source under $GOPATH/src/<import-path>. Almost every modern fix is the first one.

The Two Versions of This Error

The toolchain prints a different message per era. Identify yours first.

Module era (Go 1.11+, any directory with go.mod):

main.go:5:2: no required module provides package github.com/gorilla/mux; to add it:
        go get github.com/gorilla/mux

When the module exists but the fetch fails, you see instead:

main.go:5:2: cannot find module providing package github.com/gorilla/mux: module github.com/gorilla/mux: reading https://proxy.golang.org/...: 404 Not Found

GOPATH era (pre-1.11 layout, or builds with GO111MODULE=off):

cannot find package "github.com/gorilla/mux" in any of:
        /usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
        /home/user/go/src/github.com/gorilla/mux (from $GOPATH)

The second version means the compiler searched only two directories on disk and found nothing. If you see it in a new project, the real problem is usually an absent go.mod, not a wrong path.

Cause 1: Typo in the Import Path

The most common trigger is a misspelled or stale path.

package main

import "github.com/gorilla/muxx" // extra 'x'

Check the path against the repository README, then correct it. The module reference defines how Go resolves each element of a module path.

Cause 2: Dependency Not in go.mod

Your code imports a third-party package that no require line covers. Add it:

go get github.com/gorilla/[email protected]

Or let go mod tidy sweep every import at once:

go mod tidy

This pairs with the "missing go.sum entry" error, which appears after go get when hashes lag behind.

Cause 3: Local Module Without a Replace Directive

A local module next to your project has no published version, so go get cannot find it. Declare the location in go.mod:

module example.com/app

go 1.22

require example.com/lib v0.0.0

replace example.com/lib => ../lib

With this directive in place, imports of example.com/lib/... resolve to the local checkout. Remove the replace line before you publish, because other users cannot see your filesystem.

Cause 4: Vendored Code With an Incomplete Vendor Tree

If a vendor/ directory exists, the build reads packages from it and ignores the network. An incomplete tree produces:

main.go:5:2: package github.com/gorilla/mux is not in std (...)

or an inconsistency message about vendor/modules.txt. Refresh the whole tree:

go mod vendor

Commit vendor/ as one unit; a partial commit reproduces the error for teammates.

Cause 5: Internal Package Visibility

Packages under an internal/ element follow a special rule from the Go source layout: only code rooted at the parent of internal/ may import them.

example.com/app/internal/secrets   <- importable only inside example.com/app/...
example.com/app/internal           <- same rule

An import of example.com/other/internal/cache from example.com/app fails even though the code compiles locally for its owner. The fix is to move shared code out of internal/, or to copy what you need.

FAQ

I ran go get but still see "cannot find module providing package". Why?

Check the exact text after the colon. A 404 Not Found means no such module exists at that path — likely a typo or a retired repository. A proxy or firewall message means your network blocks the module proxy. Set GOPROXY=direct as a test.

Do I need GOPATH anymore?

No. Modules have been the default since Go 1.16. You meet the GOPATH message only inside legacy trees, or when you set GO111MODULE=off.

Related Articles

Sources

Leonardo Lazzaro

Software engineer and technical writer. 10+ years experience in DevOps, Python, and Linux systems.

More articles by Leonardo Lazzaro