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: Cannot find module providing package of custom libraries #28047

Closed
pprasanthi opened this issue Oct 6, 2018 · 3 comments
Closed

cmd/go: Cannot find module providing package of custom libraries #28047

pprasanthi opened this issue Oct 6, 2018 · 3 comments

Comments

@pprasanthi
Copy link

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/pprasanthi/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/pprasanthi/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/pprasanthi/gomodtry/tests/src/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/43/hr2mln315bgdqfyr9_bcr38r0000gn/T/go-build210705843=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

1.	find the repo in https://github.com/pprasanthi/gomodtry
2.	export GO111MODULE=on
3.	cd /tmp/gomodtry/tests/src
4.	go mod init github.com/pprasanthi/gomodtry
5.	go get github.com/stretchr/testify/assert
6.	This added the dependencies in go.mod and go.sum was created.
7.	⁃	module github.com/pprasanthi/gomodtry

require (
    github.com/davecgh/go-spew v1.1.1 // indirect
    github.com/pmezard/go-difflib v1.0.0 // indirect
    github.com/stretchr/testify v1.2.2
)
8.	go test ./… throws error:
⁃	pprasanthi-MBP-A6F84:src pprasanthi$ go test ./... -v
⁃	# github.com/pprasanthi/gomodtry/hello
⁃	hello/hello_test.go:5:2: unknown import path "lib/helper": cannot find module providing package lib/helper
⁃	github.com/pprasanthi/gomodtry/hello [setup failed]
⁃	?   	github.com/pprasanthi/gomodtry/lib/helper	[no test files]
9.	The tests work fine, when 
⁃	unset GO111MODULE
⁃	export GOPATH=/tmp/gomodtry/tests:/tmp/gomodtry/tests/src/lib/
⁃	go get github.com/stretchr/testify/assert
⁃	go test ./… -v 
⁃	
10.	Why am I getting error when I set GO111MODULE and run tests, how to fix it?

If possible, provide a recipe for reproducing the error.
https://github.com/pprasanthi/gomodtry

What did you expect to see?

I want my tests to run without failures.

What did you see instead?

$ go test ./... -v
⁃ # github.com/pprasanthi/gomodtry/hello
⁃ hello/hello_test.go:5:2: unknown import path "lib/helper": cannot find module providing package lib/helper
⁃ github.com/pprasanthi/gomodtry/hello [setup failed]
⁃ ? github.com/pprasanthi/gomodtry/lib/helper [no test files]

@thepudds
Copy link
Contributor

@gopherbot, please add label modules

@thepudds
Copy link
Contributor

@pprasanthi I'm not 100% sure what the exact issue is here, but a few quick comments.

It looks like you might not be including domain names in your import paths? For example, here:

https://github.com/pprasanthi/gomodtry/blob/master/tests/src/hello/hello_test.go

import (
	"github.com/stretchr/testify/assert"
	"lib/helper"
	"testing"
)

If so, that could be one source of issues. See some related discussion here regarding domain names and dots in import paths and modules in #27503, including this comment from @bcmills:

Dotless paths in general are reserved for the standard library; go get has (to my knowledge) never worked with them, but go get is also the main entry point for working with versioned modules.

Also note that relative imports like import "./subdir" do not work with modules. See for example #26645 (comment).

Do you think either of those might explain what you are seeing?

Sorry if this is not a 100% helpful comment, but just trying to see if a question or two might help advance the conversation here...

@myitcv myitcv changed the title Cannot find module providing package of custom libraries cmd/go: Cannot find module providing package of custom libraries Oct 21, 2018
@bcmills
Copy link
Contributor

bcmills commented Jan 17, 2019

This is working as designed.

go mod init github.com/pprasanthi/gomodtry tells the go command that all of the packages within that module begin with the prefix github.com/pprasanthi/gomodtry.

The import in hello_test.go lacks that prefix, so it cannot be found within the module.

In module mode, you must always use fully-qualified import paths.

@bcmills bcmills closed this as completed Jan 17, 2019
@golang golang locked and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants