flyx
flyx

Reputation: 39638

How to prevent go mod tidy from looking up a replaced module path

Consider the following setup:


go.mod

module example.com/main

require example.com/sub dummy
replace example.com/sub => ./sub

sub/go.mod

module example.com/sub

If I run go mod tidy in the main directory, it emits

go: errors parsing go.mod:
[…]/go.mod:3: unrecognized import path "example.com/sub": reading https://example.com/sub?go-get=1: 404 Not Found

Even if the URL existed, my understanding is that due to the replace directive, go mod has no business whatsoever with the original source because I replaced it. So why is it querying the source then? And how can I prevent that?

I already tried to set GOPROXY=off which resulted in

[…]/go.mod:3: module lookup disabled by GOPROXY=off

Upvotes: 7

Views: 6798

Answers (2)

VonC
VonC

Reputation: 1323115

Looking at go mod tidy, try first (Go 1.16+, from issue 26603):

go mod tidy -e

The -e flag makes tidy attempt to proceed despite errors encountered while loading packages.

Upvotes: 6

rustyx
rustyx

Reputation: 85256

Just assign a proper version number like v0.0.0 and it will work.

Go modules use the semantic versioning model and cannot have arbitrary versions like dummy. The supported version formats are described in Module version numbering.


Bonus note: avoid nesting Go modules. That may lead to a messy setup and problems with tooling down the road.

Upvotes: 4

Related Questions