Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go.mod cannot be in drive root folder on Windows #51506

Open
cwmos opened this issue Mar 5, 2022 · 7 comments
Open

cmd/go: go.mod cannot be in drive root folder on Windows #51506

cwmos opened this issue Mar 5, 2022 · 7 comments
Labels
help wanted modules NeedsInvestigation OS-Windows
Milestone

Comments

@cwmos
Copy link

@cwmos cwmos commented Mar 5, 2022

What version of Go are you using (go version)?

go version go1.17.8 windows/amd64

Does this issue reproduce with the latest release?

I believe this is the latest stable release.

What operating system and processor architecture are you using (go env)?

go env Output
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\XXX\AppData\Local\go-build
set GOENV=C:\Users\XXX\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\XXX\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\XXX\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.8
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\XXX\AppData\Local\Temp\go-build3973278424=/tmp/go-build -gno-record-gcc-switches

What did you do?

I placed my go.mod file in the root folder of a drive and placed my main package in a subfolder. I then ran "go build" in the subfolder.

What did you expect to see?

I expected my program to compile

What did you see instead?

The go compiler outputed this error:

directory . outside available modules
@cwmos cwmos changed the title go.mod cannot be in driver root folder on Windows go.mod cannot be in drive root folder on Windows Mar 5, 2022
@cwmos cwmos changed the title go.mod cannot be in drive root folder on Windows go/compile: go.mod cannot be in drive root folder on Windows Mar 6, 2022
@ALTree ALTree changed the title go/compile: go.mod cannot be in drive root folder on Windows go/go: go.mod cannot be in drive root folder on Windows Mar 6, 2022
@ALTree ALTree added NeedsInvestigation OS-Windows modules labels Mar 6, 2022
@ALTree ALTree added this to the Unplanned milestone Mar 6, 2022
@bcmills bcmills modified the milestones: Unplanned, Backlog Mar 8, 2022
@bcmills
Copy link
Member

@bcmills bcmills commented May 11, 2022

@cwmos, it's possible that this may have been fixed by the change to str.TrimFilePathPrefix in CL 396694. Could you try a go built from head (see https://go.dev/doc/install/source) or gotip and check whether it still reproduces?

@bcmills bcmills added the WaitingForInfo label May 11, 2022
@cwmos
Copy link
Author

@cwmos cwmos commented May 11, 2022

I tried with gotip and there is still the same issue. The error message has changed to:

directory . outside main module or its selected dependencies

@bcmills bcmills added help wanted and removed WaitingForInfo labels May 12, 2022
@mattn
Copy link
Member

@mattn mattn commented May 12, 2022

I'm trying this with HEAD.

image

@cwmos
Copy link
Author

@cwmos cwmos commented May 12, 2022

@mattn , you need to build in a subfolder
Untitled

@mattn
Copy link
Member

@mattn mattn commented May 12, 2022

I could repro.

@gopherbot
Copy link

@gopherbot gopherbot commented May 12, 2022

Change https://go.dev/cl/405934 mentions this issue: cmd/go/internal/modload: check path prefix with correct module root.

@mattn
Copy link
Member

@mattn mattn commented May 12, 2022

When go.mod is located on root directory, go compiler check the module prefix with C:\\ and C:\foo.

@seankhliao seankhliao changed the title go/go: go.mod cannot be in drive root folder on Windows cmd/go: go.mod cannot be in drive root folder on Windows Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted modules NeedsInvestigation OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants