Closed
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
1.11
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
❯ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/andig/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/andig/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/andig/htdocs/goelster/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/73/89ycv7qn51j4kbm04jsz9b840000gn/T/go-build453007721=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Trying to init go modules, I'm seing it fail from one folder but working from another. Both folders only contain two simple go files:
~/htdocs/canprogs/go master*
❯ go mod init
go: cannot determine module path for source directory /Users/andig/htdocs/canprogs/go (outside GOPATH, no import comments)
~/htdocs/goelster master
❯ go mod init
go: creating new go.mod: module github.com/andig/goelster
❯ ls
elster.go main.go
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
bcmills commentedon Oct 1, 2018
Please attach the output of
go env
(as requested by the issue template).bcmills commentedon Oct 1, 2018
Which directory (if any) is at the root of your VCS checkout, and what is your
GOPATH
?[-]go mod init fails[/-][+]cmd/go: go mod init fails in subdirectory[/+][-]cmd/go: go mod init fails in subdirectory[/-][+]cmd/go: go mod init fails to determine module path in subdirectory[/+]andig commentedon Oct 1, 2018
Sorry, only noticed the "operating system" question, added
go env
above.~/htdocs/canprogs
is a git root, so is~/htdocs/goelster
. Neither is part of the gopath.andig commentedon Oct 4, 2018
@bcmills I see this has been scheduled- seems I've hit an actual issue here?
xswordsx commentedon Oct 10, 2018
Have you tried
go mod init <module_name>
? (e.g.go mod init goelster
)andig commentedon Oct 13, 2018
That creates a go.mod:
is this the expected behavior?
myitcv commentedon Nov 13, 2018
go mod init
with no arguments does it's best to determine a module path if the current directory belongs to a VCS repository that has a remote:You can alternatively provide an explicit argument, as you outlined in #27951 (comment).
The bug you correctly identified is that
go mod init
with no arguments does not do the correct thing in a subdirectory of the VCS repo root:12 remaining items
mxork commentedon Mar 28, 2019
maybe a hint towards the correct command?
I'd 👍 for expanding
go help mod init
as an alternative.iwdgo commentedon Mar 31, 2019
go get
is supporting several VCS including other git platforms. It is unclear from the online documentation about modules and its FAQ answer that support seems currently limited to github as the regex and its use above implies. Mentioning the current limit would improve the understanding of the message.bcmills commentedon Apr 1, 2019
@iwdgo, to be honest, I'm not sure that inferring
github.com
paths is really the right behavior either. Some of those are served through other import paths (via redirects and/or<meta>
tags), sogo mod init
can very easily pick the wrong path.The right solution might be to remove the
github.com
special-case and always require an explicit path when outside of GOPATH.iwdgo commentedon Apr 3, 2019
I agree that best effort to locate path is confusing and removal seems most appropriate.
A default value set to the folder name where the module resides could be considered but might be the subject of a separate issue. The behavior would become similar to the
$GOPATH
related code which sets a value only when the module resides in$GOPATH/src/<module-path>
The discussed message would be irrelevant and could be replaced with "default module path set to ".
rsc commentedon Apr 9, 2019
Killing the github.com special case seems fine. I would like to leave all the other, better, higher-priority auto-deriving of module paths, since those are much more accurate and helpful.
gopherbot commentedon Apr 14, 2019
Change https://golang.org/cl/172019 mentions this issue:
cmd/go: remove auto-deriving module path for github.com
joshuamkite commentedon Apr 14, 2019
I have been able to resolve this with code in a repo subdir with
Surely this can be automated?!
Issue (golang/go#27951) is closed
SunSparc commentedon May 17, 2019
This solved it for me! Thank you @joshuamkite!!
qhkm commentedon Sep 28, 2019
This solved for me too. Thanks!!
mrchuanxu commentedon Nov 14, 2019
why is go mod init pwd solved? why?
bcmills commentedon Nov 15, 2019
go mod init `pwd`
is highly unlikely to be correct: the argument togo mod init
is a module path, butpwd
is generally an absolute filesystem path. (See #28389.)If the
go
command cannot determine an appropriate module path, the general solution is no pass one explicitly. See https://golang.org/cmd/go/#hdr-Defining_a_module and https://blog.golang.org/using-go-modules.