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: can't use "replace" directive on Windows #32215

Closed
hach-que opened this issue May 23, 2019 · 7 comments
Closed

cmd/go: can't use "replace" directive on Windows #32215

hach-que opened this issue May 23, 2019 · 7 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@hach-que
Copy link

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

$ go version
go version go1.12.5 windows/amd64

Does this issue reproduce with the latest release?

Yes, it happens on go version go1.12.5 windows/amd64.

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

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\June Rhodes\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\June Rhodes\go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\June Rhodes\Documents\Projects\next\services\publisher\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\JUNERH~1\AppData\Local\Temp\go-build120035906=/tmp/go-build -gno-record-gcc-switches

What did you do?

The directory structure looks like this:

- publisher
  - config
    - config.pb.go
  - publisher.go

I'm trying to import the config subdirectory as a module.

June Rhodes@DOCTOR-STRANGE C:\Users\June Rhodes\Documents\Projects\next\services\publisher                                                                                   
$ cat go.mod                                                                                                                                                                 
module github.com/networknext/next/services/publisher                                                                                                                        
                                                                                                                                                                             
go 1.12                                                                                                                                                                      
                                                                                                                                                                             
require (                                                                                                                                                                    
        // .. snip ..                                                                                                                   
        github.com/networknext/next/services/publisher/config v0.0.0-00010101000000-000000000000                                                                             
        // .. snip ..                                                                                                                                  
)                                                                                                                                                                            
                                                                                                                                                                             
replace github.com/networknext/next/services/publisher/config => config                                                                                                      
                                                                                                                                                                             
June Rhodes@DOCTOR-STRANGE C:\Users\June Rhodes\Documents\Projects\next\services\publisher                                                                                   
$ go build                                                                                                                                                                   
go: errors parsing go.mod:                                                                                                                                                   
C:\Users\June Rhodes\Documents\Projects\next\services\publisher\go.mod:23: replacement module without version must be directory path (rooted or starting with ./ or ../)     
                                                                                                                                                                             
June Rhodes@DOCTOR-STRANGE C:\Users\June Rhodes\Documents\Projects\next\services\publisher                                                                                   
$ cat go.mod                                                                                                                                                                 
module github.com/networknext/next/services/publisher                                                                                                                        
                                                                                                                                                                             
go 1.12                                                                                                                                                                      
                                                                                                                                                                             
require (                                                                                                                                                                    
        // .. snip ..                                                                                                                    
        github.com/networknext/next/services/publisher/config v0.0.0-00010101000000-000000000000                                                                             
        // .. snip ..
)                                                                                                                                                                            
                                                                                                                                                                             
replace github.com/networknext/next/services/publisher/config => ./config                                                                                                    
                                                                                                                                                                             
June Rhodes@DOCTOR-STRANGE C:\Users\June Rhodes\Documents\Projects\next\services\publisher                                                                                   
$ go build                                                                                                                                                                   
build github.com/networknext/next/services/publisher: cannot find module for path _/C_/Users/June_Rhodes/Documents/Projects/next/services/publisher/config                   

What did you expect to see?

I expected it to build successfully.

What did you see instead?

It complains about the path "/C/Users/June_Rhodes/Documents/Projects/next/services/publisher/config" not existing.

@bradfitz bradfitz added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows release-blocker labels May 23, 2019
@bradfitz bradfitz added this to the Go1.13 milestone May 23, 2019
@bradfitz bradfitz changed the title Can't use "replace" directive on Windows cmd/go: can't use "replace" directive on Windows May 23, 2019
@bradfitz
Copy link
Contributor

/cc @bcmills

@thepudds
Copy link
Contributor

thepudds commented May 24, 2019

@hach-que is there a go.mod file located at C:\Users\June_Rhodes\Documents\Projects\next\services\publisher\config?

If not, that might explain the error. If the target of a replace statement is a filesystem path, that filesystem path must point to a directory with a go.mod.

Alternatively, within the Go code of github.com/networknext/next/services/publisher, are there any import "./config" statements? If so, relative import paths are no longer allowed with modules.

However, maybe there is something else going on that is causing that error.

If it is still a question as to the cause:

  1. What does the module line say for the ./config/go.mod file?
  2. What do the import paths say in the github.com/networknext/next/services/publisher to import the config module?

One side note: multi-module repos are generally rare. The simplest and most common structure is to instead have a single go.mod, and locate that single go.mod at the root of the repository.

Russ Cox commented in #26664:

For all but power users, you probably want to adopt the usual convention that one repo = one module. It's important for long-term evolution of code storage options that a repo can contain multiple modules, but it's almost certainly not something you want to do by default.

Here is a recent example of how multi-module repos can go a bit off the rails: ugorji/go#299

Is there a particular reason for ./config to be a separate module?

@hach-que
Copy link
Author

hach-que commented May 24, 2019 via email

@thepudds
Copy link
Contributor

thepudds commented May 24, 2019

and then eventually at some point relative package paths will stop working entirely in a newer Go
version.

Is the .go code currently using relative package import paths, such as import "./subdir"?

If so, the error message you are seeing seems to line up with #26645, where one example from there includes:

go build main.go
build .: cannot find module for path _/tmp/gomodsubdirs/subdir

which is at least somewhat similar to:

$ go build
build github.com/networknext/next/services/publisher:
cannot find module for path
/C/Users/June_Rhodes/Documents/Projects/next/services/publisher/config

@hach-que
Copy link
Author

Hmm, well I just tried to put together an example to replicate, and the example works fine on Windows:

gorepl.zip

So I must have done something wrong when I was changing the way the library was imported. I'll take another look at the code in our monorepo tonight to see what's wrong with it.

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed release-blocker labels May 28, 2019
@bcmills
Copy link
Contributor

bcmills commented May 28, 2019

I'll take another look at the code in our monorepo tonight to see what's wrong with it.

Thanks, let us know what you find. At the very least it seems like we should produce a better error message, whenever we can figure out what's causing this error message to begin with.

@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Jun 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants