Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Go: module declares its path as but was required as

A module's go.mod path must match the path the build requires. Fix forks used through replace, vanity imports, and the /v2 major version suffix rule.

~5 min readGo
#go#go-mod#modules#replace
Bold white headline reading PATH MISMATCH with a Go module crate showing two conflicting cyan path cards on the right.

Introduction & Quick Summary

go get or go build refuses a dependency:

code
go: example.com/acme/kit@v1.4.0: parsing go.mod: module declares its path as: github.com/acme-kit/kit but was required as: example.com/acme/kit

The module downloaded successfully and its own go.mod begins with a different module line than the path the build asked for. Go treats the module path as part of the module's identity, so this is a hard stop rather than a warning: proxies, checksums, and import paths all key off that string.

Where it appears:

  • A fork that changed the repository location but kept or edited the module line inconsistently.
  • A vanity import path (example.com/kit) served by a go-import meta tag that points at a repository whose go.mod says github.com/....
  • A replace directive to a fork whose go.mod declares the fork's own path.
  • A major version bump to v2 without adding /v2 to the module path.
  • A private module behind GOPRIVATE fetched through a proxy that rewrote the path.

Quick answer: make the required path and the declared path equal. Either require the path the module actually declares, or — for a fork used through replace — make the fork's go.mod keep the original module line.

Core Mechanics, Signatures & Reproducible Setup

A module is identified by the string in its go.mod:

code
module github.com/acme-kit/kit go 1.22

Every import in the ecosystem is modulePath + / + package subdirectory. When go resolves example.com/acme/kit, it fetches the repository, reads go.mod, and compares. Inequality produces the error above before any package is compiled, so build tags and code contents are irrelevant.

Reproduce it locally with two modules:

bash
mkdir -p mismatch/kit mismatch/app && cd mismatch/kit go mod init github.com/acme-kit/kit mkdir -p util && printf 'package util\n\nfunc Hello() string { return "hi" }\n' > util/util.go cd ../app go mod init example.com/acme/app cat > main.go <<'EOF' package main import ( "fmt" "example.com/acme/kit/util" ) func main() { fmt.Println(util.Hello()) } EOF go mod edit -require=example.com/acme/kit@v0.0.0 go mod edit -replace=example.com/acme/kit=../kit go build ./...
code
go: example.com/acme/kit@v0.0.0 (replaced by ../kit): parsing ../kit/go.mod: module declares its path as: github.com/acme-kit/kit but was required as: example.com/acme/kit

The replace did not help, because replacement changes where the code comes from, not what it must call itself.

The three ways the paths can disagree, and the fix for each:

SituationDeclaredRequiredFix
fork used via replacefork's own pathoriginal pathchange the fork's go.mod to the original path
vanity importrepository pathvanity pathserve a correct go-import meta tag, or require the repository path
major version bumpexample.com/libexample.com/lib/v2add /v2 to the module line and imports

Key Comparison Table

Choosing between the three legitimate resolutions:

ApproachChange requiredProsCons
Require the declared pathupdate imports and go.modno forks, checksums match upstreamimport paths change in code
Fix the fork's module lineedit fork go.mod, keep replacedrop-in replacement, imports untouchedfork diverges from upstream metadata
Publish under a vanity domaingo-import meta tag plus module linestable path, can move hosts laterDNS or HTTP dependency

Which layer reports the problem:

CommandMessage prefixMeaning
go get example.com/x@v1go: example.com/x@v1: parsing go.modresolution time mismatch
go build with replace(replaced by ../dir)local or forked replacement mismatch
go mod tidygo: ... requires ...transitive dependency mismatch
go list -m allmodule declares its path asalready in the module graph

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Forks that must be drop-in replacements

The reason forks keep the upstream module line is precisely this check. A fork that adds a fix should look like this:

code
module github.com/original/kit go 1.22

even though the repository lives at github.com/acme-kit/kit. The consumer then writes:

code
require github.com/original/kit v1.4.0 replace github.com/original/kit => github.com/acme-kit/kit v1.4.1

Two details make this work: the fork must be tagged (v1.4.1), and the replace target needs a version because the fork is a module in a repository whose path differs. Without the version, Go reports replacement module without version must be directory path.

2. Vanity import paths

example.com/kit resolves through an HTML meta tag:

html
<meta name="go-import" content="example.com/kit git https://github.com/acme-kit/kit">

If the repository's go.mod says module github.com/acme-kit/kit, the fetch fails with the mismatch error. The module line must be the vanity path:

module example.com/kit

The repository name and the module path are independent; the meta tag is what ties them together. Changing the vanity host later requires a redirect that keeps serving the old tag, or every consumer breaks.

3. Major versions and the /vN suffix

From v2 onward, the module path must end in /v2 (or /v3, and so on):

code
module example.com/lib/v2 go 1.22

Imports become example.com/lib/v2/pkg. A tag v2.0.0 on a module whose path has no suffix is rejected with module path must be ... /v2 or the mismatch message depending on how it is reached. The suffix is part of the path, not a version selector, so v2 and v1 can coexist in one build:

code
require ( example.com/lib v1.9.0 example.com/lib/v2 v2.3.0 )

That coexistence is the intended benefit of the rule, and it is the reason the suffix cannot be faked with a replace.

4. Private modules and proxy rewriting

A GOPROXY that serves a mirrored module with a rewritten path produces the same error, with the proxy host in the required string:

code
go: proxy.internal/example.com/kit@v1.0.0: parsing go.mod: module declares its path as: example.com/kit

Fix the proxy configuration rather than the module: the mirror must preserve the original path, and GONOSUMDB/GOPRIVATE must list the private host so checksums are not fetched from the public sum database.

bash
go env GOPROXY GOPRIVATE GONOSUMDB GOFLAGS

Print those four values before debugging further; a stale GOPROXY in a shell profile explains most "works on my machine" reports.

5. When the error hides a case-sensitivity problem

GitHub.com/Acme/Kit in go.mod versus github.com/acme/kit in an import produces a mismatch on a case-sensitive filesystem and can appear to work on a case-insensitive one. Go module paths are case-sensitive by specification and use ! escaping in the module cache (github.com/!acme/!kit). Copy paths from go list -m output rather than retyping them.

Common Compilation/Runtime Mistakes & Version Gotchas

Editing go.mod by hand in the consumer only. Changing the require line to the declared path works, and then every import in the code must change too. Let go mod edit -require= plus a search-and-replace over imports do both, and run go build ./... to confirm nothing was missed.

Using replace to mask a version problem. replace example.com/kit => ../kit is convenient during development and dangerous when it reaches a release tag: the module is then not reproducible for anyone else. Keep local replaces in a separate file included only for development, or remove them before tagging.

Assuming go.sum needs updating first. go mod tidy will not fix a path mismatch; it reports the same error. Fix go.mod, then let tidy update the sums.

Version differences worth knowing. Go 1.17 and later require explicit require blocks for every module that provides an imported package, so a missing entry shows as a build error rather than a silent fetch. Go 1.21 changed go line semantics so a go 1.21 module can use newer toolchains while still declaring a minimum. Go 1.24 added tool directives in go.mod, which produces parsing go.mod: unknown directive on older toolchains — a different parse error with the same "read the go.mod" fix.

Comparing module files. When a build works in one checkout and not another, diff the two go.mod files with Diff, and print the resolved graph with go list -m -json all (formatted with the JSON viewer) to see which exact version and path each module resolved to.

Reference material: Go modules reference and Module version numbering, major versions.

Official references

primary documentation

The Go documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Go work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Go guides

More in Go

All Go guides

The guides filed next to this one in Go, in library order.