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.

Introduction & Quick Summary
go get or go build refuses a dependency:
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/kitThe 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
moduleline inconsistently. - A vanity import path (
example.com/kit) served by ago-importmeta tag that points at a repository whosego.modsaysgithub.com/.... - A
replacedirective to a fork whosego.moddeclares the fork's own path. - A major version bump to
v2without adding/v2to the module path. - A private module behind
GOPRIVATEfetched 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:
module github.com/acme-kit/kit
go 1.22Every 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:
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 ./...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/kitThe 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:
| Situation | Declared | Required | Fix |
|---|---|---|---|
fork used via replace | fork's own path | original path | change the fork's go.mod to the original path |
| vanity import | repository path | vanity path | serve a correct go-import meta tag, or require the repository path |
| major version bump | example.com/lib | example.com/lib/v2 | add /v2 to the module line and imports |
Key Comparison Table
Choosing between the three legitimate resolutions:
| Approach | Change required | Pros | Cons |
|---|---|---|---|
| Require the declared path | update imports and go.mod | no forks, checksums match upstream | import paths change in code |
Fix the fork's module line | edit fork go.mod, keep replace | drop-in replacement, imports untouched | fork diverges from upstream metadata |
| Publish under a vanity domain | go-import meta tag plus module line | stable path, can move hosts later | DNS or HTTP dependency |
Which layer reports the problem:
| Command | Message prefix | Meaning |
|---|---|---|
go get example.com/x@v1 | go: example.com/x@v1: parsing go.mod | resolution time mismatch |
go build with replace | (replaced by ../dir) | local or forked replacement mismatch |
go mod tidy | go: ... requires ... | transitive dependency mismatch |
go list -m all | module declares its path as | already 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:
module github.com/original/kit
go 1.22even though the repository lives at github.com/acme-kit/kit. The consumer then writes:
require github.com/original/kit v1.4.0
replace github.com/original/kit => github.com/acme-kit/kit v1.4.1Two 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:
<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):
module example.com/lib/v2
go 1.22Imports 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:
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:
go: proxy.internal/example.com/kit@v1.0.0: parsing go.mod:
module declares its path as: example.com/kitFix 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.
go env GOPROXY GOPRIVATE GONOSUMDB GOFLAGSPrint 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 documentationThe Go documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Go work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Go guides
All Go guidesGo: x509 certificate signed by unknown authority
Go cannot build a chain to a trusted root: no CA bundle in the image, a private CA, or a missing intermediate. Install roots or set RootCAs.
Go: fatal error: concurrent map writes in goroutines
The runtime catches two writes to one map and stops the process. Guard access with a mutex, use sync.Map for caches, or give one owner.
Go: import cycle not allowed
Go forbids cycles in the package import graph. Break them by extracting shared types, declaring interfaces where consumed, or inverting init registration.
Go: http: superfluous response.WriteHeader call
net/http logs this when a handler writes the status twice. It almost always marks a later status write that was silently ignored, or no return.
More in Go
All Go guidesThe guides filed next to this one in Go, in library order.