go: cmd/go: "unexpected module path" error lacks enough detail to find underlying problem (docker Sirupsen/logrus mismatch)
What version of Go are you using (go version
)?
Go 1.11.1
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
Linux, amd64
Problem
Our go.mod
has the following dependency, along with many other dependencies:
github.com/sirupsen/logrus v1.1.1
When running go mod vendor
, I get the following error:
go: github.com/Sirupsen/logrus@v1.1.1: parsing go.mod: unexpected module path "github.com/sirupsen/logrus"
I suspect that some deeper indirect dependency is also using logrus, but with the incorrect (old) capital S. However, the error message isn’t giving me enough detail to track it down. It would be nice if the tool gave me a list of the modules or packages that are using the conflicting import path.
Example
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 64
- Comments: 36 (20 by maintainers)
Commits related to this issue
- rename `Sirupsen` to lower case in order to resolve https://github.com/golang/go/issues/28489 — committed to goFrendiAsgard/go-skeleton by goFrendiAsgard 5 years ago
- Update Sirupsen/logrus path to match current name (sirupsen/logrus) This should clean things up and mitigate a potential future issue when upgrading to Go Modules (as seen in https://github.com/golan... — committed to square/keysync by mbyczkowski 5 years ago
- Update several mods (#460) In response to https://github.com/golang/go/issues/28489#issuecomment-479107647 We need to update `go get -u github.com/docker/distribution` In response to https://gith... — committed to kolide/launcher by directionless 5 years ago
- cmd/go: tweak wording of module path mismatch error message Changes "was loaded as" to "was required as". This is slightly more precise, since it hints at a requirement edge in the module version gra... — committed to golang/go by deleted user 5 years ago
- dep: out with glide, in with gomods This required bump of some external dependencies, in order to get rid of old versions of logrus as derived depedency. see issues: - https://github.com/sirupsen/lo... — committed to DBCDK/shelob by deleted user 5 years ago
- dep: out with glide, in with gomods This required bump of some external dependencies, in order to get rid of old versions of logrus as derived dependency. see issues: - https://github.com/sirupsen/l... — committed to DBCDK/shelob by deleted user 5 years ago
- dep: out with glide, in with gomods This required bump of some external dependencies, in order to get rid of old versions of logrus as derived dependency. see issues: - https://github.com/sirupsen/l... — committed to DBCDK/shelob by deleted user 5 years ago
- upstream: Sirupsen -> sirupsen name change In 2018 the GitHub "organization" github.com/Sirupsen changed to all lower case. While this was fine in a pre "Go Modules" world, this cases breaking chang... — committed to brianredbeard/fetch-ssh-keys by brianredbeard 4 years ago
- Add better fix for docker term package **What** - Update module replace so that modules _just work_ . This uses the fix described here https://github.com/golang/go/issues/28489#issuecomment-5281229... — committed to LucasRoesler/faas-cli by LucasRoesler 4 years ago
- Add better fix for docker term package **What** - Update module replace so that modules _just work_ . This uses the fix described here https://github.com/golang/go/issues/28489#issuecomment-5281229... — committed to LucasRoesler/faas-cli by LucasRoesler 4 years ago
- Add better fix for docker term package **What** - Update module replace so that modules _just work_ . This uses the fix described here https://github.com/golang/go/issues/28489#issuecomment-5281229... — committed to LucasRoesler/faas-cli by LucasRoesler 4 years ago
if anyone encounters this issue again, a simple solution is to add the following to your
go.mod
file:replace github.com/Sirupsen/logrus v1.4.2 => github.com/sirupsen/logrus v1.4.2
Replace the version with whatever you need to use.
Have you tried
go mod why
?@maguro in my case I rename all “Sirupsen” to “sirupsen” from my dependencies
@maguro, a TL;DR workaround to what? The issue reported here is a less-than-helpful error message, but presumably the thing you want to work around is some error itself⸮
It produces the same error with no additional info.
I should note that I am using a very recent pseudo-version of docker in my example, and the problem still occurs:
github.com/docker/docker v0.7.3-0.20181027010111-b8e87cfdad8d
Ideally, docker should start using
go.mod
and tag its repo correctly, but in the meantime, it would be nice to get more details from the error message so these sorts of problems are easier to diagnose. Nothing in the error message indicates that the conflict is coming from docker or one of its dependencies.The underlying cause here is almost certainly the same as https://github.com/golang/go/issues/26208, although per the description, not obviously so. Not least because time (and releases) have passed since that issue was reported.
There are a number of issues/factors at play here:
github.com/docker/docker
does not follow semver so we need to do a separatego get
for the latest version of thatgithub.com/docker/docker@v17.05.0-ce
(for example) is not a modulegithub.com/docker/docker@v17.05.0-ce
’s dependencies are managed viavendor.conf
and are sufficiently esoteric (dependencies not using semver, etc) that we need togo mod init
and “merge” those dependencies into our main module’sgo.mod
github.com/Sirupsen/logrus
vsgithub.com/sirupsen/logrus
is a long standing issue. GitHub redirectsgithub.com/Sirupsen/logrus
togithub.com/sirupsen/logrus
github.com/sirupsen/logrus
/github.com/Sirupsen/logrus
is now a module,github.com/sirupsen/logrus
. Hence in module mode:github.com/Sirupsen/logrus
is used as such consistently ingithub.com/docker/docker@v17.05.0-ce
and all its dependencies. This means that any use ofgithub.com/sirupsen/logrus
in module mode is a problem (case-insensitive import collision: "github.com/sirupsen/logrus" and "github.com/Sirupsen/logrus"
) but also that we need to usegithub.com/Sirupsen/logrus
(sic) prior to v1.1.0 when it became the modulegithub.com/sirupsen/logrus
Hence we end up needing to do something like the following (notice we get the pre v1.1.0 version of
github.com/Sirupsen/logrus
/github.com/sirupsen/logrus
via thegomodmerge
):https://gist.github.com/myitcv/f7270ab81ab45aa286f496264f034b56
To my mind, the v1.1.0 module-enabled release of
github.com/Sirupsen/logrus
/github.com/sirupsen/logrus
is a breaking change; because an import path ofgithub.com/Sirupsen/logrus
now no longer works when in module mode (the irony). Hence I think the module release ofgithub.com/Sirupsen/logrus
/github.com/sirupsen/logrus
should in fact have been a v2 release.So one potential way forward here is for
github.com/Sirupsen/logrus
/github.com/sirupsen/logrus
to create a new v1 release that reverts the conversion to Go modules and instead releasegithub.com/sirupsen/logrus/v2
as a module.cc @bcmills and @rsc for any additional thoughts here.
And I was just shown another way around this problem by a colleague (dropping this here for other poor souls who got stuck):
After this the problems disappeared.
Main issue were apparently old some old/unused deps causing the clash.
CL 166984 should help with build and list commands. It produces output like this (from the test):
That at least tells you which module has the unexpected import.
Unfortunately, this doesn’t produce intelligible output for
go get -u
because we don’t preserve the relationships between modules when upgrading the build list. More refactoring needed there.I just hit this issue, but the above solution did not work for me. What did work was the solution in this very helpful comment by @kolyshkin: https://github.com/moby/moby/issues/39302#issuecomment-504146736
For me, that meant the following:
main.go (or whatever you’re using)
go.mod
cc @leelynne and @lynncyrin
@bcmills
I think a better error would go a long way.
I think this is the same issue with
docker/libcompose
, wherego mod tidy
andgo mod why
were both erroring out prior to saying where the conflict came from. In other words, this error (from usingdocker/libcompose
) doesn’t tell you the real culprit:go: github.com/Sirupsen/logrus@v1.2.0: parsing go.mod: unexpected module path "github.com/sirupsen/logrus"
It seems like there is already a reproduction here, but here is a simple one showing
go mod tidy
fail for alibcompose
client:CC @vito-c
@Liamsi There has been a change in Go tip to make the output better, see https://github.com/golang/go/issues/28489#issuecomment-473297974 above. You can try Go tip via
go get golang.org/dl/gotip
. (h/t to @FiloSottile for making it!)@jayschwa ta; adjusted commit to align with that.
In https://github.com/golang/go/issues/28489#issuecomment-434616301 above, @myitcv has a very nice explanation of the somewhat common issue one can hit with docker with a uppercase/lowercase mismatch between
github.com/Sirupsen/logrus
vs.github.com/sirupsen/logrus
, and he also has a worked example there.The starting point for that worked example above happens to be a docker version from ~18 months ago (in part because of the way docker has been tagging their releases and moving repos around, as touched upon above), and the worked example above ends up with
github.com/Sirupsen/logrus
(the uppercase version) because that worked example shows finding a consistent set of older versions.Here is a worked example using a more recent docker version, and ends up with
github.com/sirupsen/logrus
(the lowercase version), using a simpledocker/libcompose
client that initially fails with:The following FAQ covers the technique in a bit more detail:
“FAQ: I have a problem with a complex dependency that has not opted in to modules. Can I use information from its current dependency manager?”
First, we clone
libcompose
in order to rungo mod init
to convert from thevendor.conf
fromlibcompose
to a temporarygo.mod
, and then use those results to populate therequire
directives for our client. Here is a worked example of doing that (with a 2018 version of libcompose and docker):Worked Example: Steps and Results
Awesome, will check that out! Thank you! Update: That change actually resolved the issue I had. Also, thanks for the reminder for gotip.
I think it’s actually fine to keep the change in
v1
. Code that uses the “wrong” import path forv1
in is already broken in general anyway: if you try to import the same module with two different cases, you’ll get a case-sensitive import collision (https://github.com/golang/go/issues/26208#issuecomment-411955266), so if we allow modules that depend on each path individually build successfully, they still can’t be combined: they aren’t really “modular”.