Skip to content

cmd/go: mod init should not infer a path with a /v1 suffix  #73121

Open
@chenyanchen

Description

@chenyanchen

Go version

go version go1.24.1 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/***/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/***/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/tp/t2jb95_s2_52x00_183fbc2h0000gn/T/go-build470510512=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/***/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/***/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.1/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/***/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

In ${GOPATH}/src

$ mkdir -p example.com/project/v1
$ cd example.com/project/v1
$ go mod init example.com/project/v1
go: invalid module path "example.com/project/v1": major version suffixes must be in the form of /vN and are only allowed for v2 or later:
	go mod init example.com/project/v2
$ go mod init
go: creating new go.mod: module example.com/project/v1
$ cat go.mod
module example.com/project/v1

go 1.24.1

What did you see happen?

go mod init example.com/project/v1 failed

go mod init success

What did you expect to see?

Refer the go mod init example.com/project/v1 error, go mod init should failed too.

Activity

chenyanchen

chenyanchen commented on Apr 1, 2025

@chenyanchen
Author

The inferred path should be checked

if modPath == "" {
var err error
modPath, err = findModulePath(modRoot)
if err != nil {
base.Fatal(err)
}
} else if err := module.CheckImportPath(modPath); err != nil {

added
BugReportIssues describing a possible bug in the Go implementation.
on Apr 1, 2025
changed the title [-]`go mod init` cannot init `v1` suffix module, but can infer go module path[/-] [+]cmd/go: mod init should not infer a path with a /v1 suffix [/+] on Apr 1, 2025
seankhliao

seankhliao commented on Apr 1, 2025

@seankhliao
Member

do you want to send a change?

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Apr 1, 2025
chenyanchen

chenyanchen commented on Apr 2, 2025

@chenyanchen
Author

do you want to send a change?

I will try

gopherbot

gopherbot commented on Apr 3, 2025

@gopherbot
Contributor

Change https://go.dev/cl/662438 mentions this issue: cmd/go/internal/modload: don't infer a /v1 suffix module path

added this to the Go1.25 milestone on Apr 10, 2025
added
FixPendingIssues that have a fix which has not yet been reviewed or submitted.
and removed
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.GoCommandcmd/go

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @gopherbot@seankhliao@samthanawalla@chenyanchen@gabyhelp

    Issue actions

      cmd/go: mod init should not infer a path with a /v1 suffix · Issue #73121 · golang/go