using go modules replace with old repos

568 views
Skip to first unread message

John Shahid

unread,
Aug 29, 2018, 11:59:20 PM8/29/18
to golang-nuts
Hi all,

Is there a way to use the go module `replace' directive for packages
that don't have go.mod yet ? I tried doing that and I get the following
error:

> go: parsing ../pkg/go.mod: open /path/to/pkg/go.mod: no such file or
> directory

According to https://github.com/golang/go/issues/24110 it looks like
this is the intended behavior. My question is why the go tool (e.g. go
get) can deal with such package when downloading it from github and
could give it a pseudo version without a go.mod file but refuses to when
the source code is local.

I'm happy to construct a sample github project to repro the issue if
that is needed.

Thanks,

-js

John Shahid

unread,
Sep 14, 2018, 10:09:00 AM9/14/18
to golang-nuts

Ping.

Paul Jolly

unread,
Sep 17, 2018, 5:54:02 AM9/17/18
to jvsh...@gmail.com, golan...@googlegroups.com
Hi John,

When using a replace target that is a local filepath, yes, the target
does need to be a module (this is in effect simulated by the go tool
when a "module" is fetched from a remote VCS in case a project is not
a module).

That's fixed in the most simple cases by creating a go.mod file in the
target directory, either:

go mod init
go mod init example.com/blah

Depending on your workflow, you might also be interested in
https://github.com/rogpeppe/gohack which was created to experiment
with workflows around working on local module replace-ments.

Thanks,


Paul
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages