btcd: ambiguous import: found package github.com/btcsuite/btcd/chaincfg/chainhash in multiple modules
Hello,
I am using the beta version (btcd@v0.22.0-beta) and recently I got this error while building
github.com/btcsuite/btcd/btcec tested by
github.com/btcsuite/btcd/btcec.test imports
github.com/btcsuite/btcd/chaincfg/chainhash: ambiguous import: found package github.com/btcsuite/btcd/chaincfg/chainhash in multiple modules:
github.com/btcsuite/btcd v0.22.0-beta (/Users/madhurshrimal/go/pkg/mod/github.com/btcsuite/btcd@v0.22.0-beta/chaincfg/chainhash)
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0 (/Users/madhurshrimal/go/pkg/mod/github.com/btcsuite/btcd/chaincfg/chainhash@v1.0.0)
It didn’t use to come before and suddenly it popped up. Any idea how I can solve this?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 9
- Comments: 51 (26 by maintainers)
Commits related to this issue
- go.mod: upgrade btcec and add 'chainhash' module requirement (#24700) See ethereum/go-ethereum#24554 and btcsuite/btcd#1839 This is an attempt to resolve a Go module dependency issue that arises ... — committed to ethereum/go-ethereum by fjl 2 years ago
- go.mod: upgrade btcec and add 'chainhash' module requirement (#24700) See ethereum/go-ethereum#24554 and btcsuite/btcd#1839 This is an attempt to resolve a Go module dependency issue that arises ... — committed to tothemoney/tmy by fjl 2 years ago
- Merge/v1.10.18 (#63) * params: begin v1.10.18 release cycle * rlp: fix typo in comment (#24595) Co-authored-by: Yong Yang <yangyong775654@163.com> * core/state/snapshot: clean up the generat... — committed to blocknative/go-ethereum by AusIV 2 years ago
- Merge v1.10.19 (#1) * core/types: improve error for too short transaction / receipt encoding (#24256) Co-authored-by: Felix Lange <fjl@twurst.com> * rlp, trie: faster trie node encoding (#241... — committed to bgelb/go-ethereum by bgelb 2 years ago
- merge stage into prod (#65) * add workflow to build binaries on release * Merge/v1.10.18 (#63) * params: begin v1.10.18 release cycle * rlp: fix typo in comment (#24595) Co-authored-by: Y... — committed to blocknative/go-ethereum by dmarzzz 2 years ago
- Merge/v1.10.19 (#64) * params: begin v1.10.18 release cycle * rlp: fix typo in comment (#24595) Co-authored-by: Yong Yang <yangyong775654@163.com> * core/state/snapshot: clean up the generat... — committed to blocknative/go-ethereum by AusIV 2 years ago
- mod: update btcd to work around ambiguous import Update btcd from v0.22.0-beta to v0.22.1 per the instructions on https://github.com/btcsuite/btcd/issues/1839 to work around an ambiguous import via g... — committed to mvdan/blind-csp by mvdan 2 years ago
- mod: update btcd to work around ambiguous import Update btcd from v0.22.0-beta to v0.22.1 per the instructions on https://github.com/btcsuite/btcd/issues/1839 to work around an ambiguous import via g... — committed to vocdoni/blind-csp by mvdan 2 years ago
- go.mod: upgrade btcec and add 'chainhash' module requirement (#24700) See ethereum/go-ethereum#24554 and btcsuite/btcd#1839 This is an attempt to resolve a Go module dependency issue that arises whe... — committed to cp-yoonjin/go-wemix by fjl 2 years ago
- go.mod: upgrade btcec and add 'chainhash' module requirement (#24700) See ethereum/go-ethereum#24554 and btcsuite/btcd#1839 This is an attempt to resolve a Go module dependency issue that arises whe... — committed to wemixarchive/go-wemix by fjl 2 years ago
The same here, what worked for me was forcing the version of
btcdandgo-ethereumat go.modConfirmed the issues are now resolved:
Also the documentation is correct again as expected.
I was having the same issue building a downstream script that uses
ethclient(four or five layers removed frombtcsuite/btcd/chaincfg/chainhash).I solved it by forcing go.mod to resolve the package to the latest version (
v1.0.0), by appending:require github.com/btcd/chaincfg/chainhash v1.0.0in mygo.modPretty sure the issue in gossamer is the require on the old btcutil module that requires an old btcd. I think you’ll want to change your btcutil import:
and update your import paths too e.g.
etc
Glad you got this resolved @shrimalmadhur! I’m not entirely sure your
go getis needed or doing what’s intended in your deps target given it’s purposed change in recent Go versions to specifically updating the go.mod rather than building anything, but as long as you’ve got things building without hacks, I’m very pleased with the resolution.Pushed a new tag here after the merge of #1851: https://github.com/btcsuite/btcd/releases/tag/v0.22.1
All consumer now should be able update to that tag, and then freely use the new
chainhashandbtcecmodules w/o the import ambiguity weirdness.From looking into this a bit there are a few issues at play and the cleanest way to resolve them, basing on my experience with managing all of the dcrd modules for a few years now is that what @chappjc recapped is the best way to resolve the issue.
Namely, as can be seen in the module release workflow docs, versions without pre-release components are preferred over those with them. In other words,
v0.22.0-betais seen as beforev0.18.1, so currently anyone just importing or doing a plaingo get github.com/btcsuite/btcdis going to attempt to getv0.18.1which is a broken version. Addressing that first issue implies that a new tag without a pre-release version on it is required.Next, the latest pre-release tag
v0.22.0-betahaschaincfg/chainhashas a package, but there is also now a separate module with the same path. This is 100% guaranteed to break consumers who try to use bothv0.22.0-betaand anything that simultaneously uses the new module such asbtcec/v2, which there are already consumers in the ecosystem that need to do that. Addressing that issue also requires a new tag that is seen as later thanv0.18.1in which thechaincfg/chainhashpackage has been removed.Finally, since there are a lot of other breaking changes and changes that are not necessarily ready for a release, what is really needed is a new e.g.
v0.23.0tag that is code branched off ofv0.22.0-betawith only the problematic package removed and the code updated to use the module instead.That way
v0.23.0will be seen as the latest release module by consumers, it will not have the package that is causing conflicts in it, and it will not include a bunch of code that is not yet ready for release.You could also opt for a
v0.22.1, btw, since it will be seen as newer as well. The important parts are that:chaincfg/chainhashmodule and not contain thechaincfg/chainhashpackageEDIT: Note that this approach will also fix the fact that https://pkg.go.dev/github.com/btcsuite/btcd is showing
v0.14.6and the incorrect README and all.@richardbertozzo yea seems like it happens when I upgrade
go-ethereumtov1.10.17keeping thebtcdversion constant. I want to update to the newer version due to a security update https://github.com/coinbase/rosetta-sdk-go/security/dependabot/1@erwanor adding that line to
go.modis still not helping my case.