How to import a local module *without* re-downloading the imported module's dependencies?

I have a module sample_project, which has a go.mod like this:

module sample_project

go 1.21.6

replace local.mod/module_to_import => ../module_to_import

require (
	github.com/ethereum/go-ethereum v1.13.11
        ...
)

But module_to_import has a replacement for github.com/ethereum/go-ethereum because it uses the arbitrum version of ethereum-go, which has some arbitrum-related stuff (types, functions, etc).
Here’s its go.mod:

module module_to_import

go 1.21.6

replace github.com/ethereum/go-ethereum => ./go-ethereum

require (
        ...
)

Now, this is sample_project’s main.go:

import (
	...
	imported_utils "local.mod/module_to_import/utils"
)

The problem is that when doing go run main.go, it will attempt to download all the packages required by module_to_import and I get an error like this:

module github.com/ethereum/go-ethereum@latest found (v1.13.11), but does not contain package github.com/ethereum/go-ethereum/arbitrum_types

I want to use the local package which resides in ../module_to_import/go-ethereum. How can I do it?

I think (but am not certain) that adding your own go-ethereum replacement will do the trick. Have tyou tried that?

  • For managing large projects with shared modules, consider package management tools like pip 's --editable flag or replace directive in requirements.txt to install local modules in editable mode, referencing their source directories directly.