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 error while go build #34985

Closed
qzyse2017 opened this issue Oct 18, 2019 · 11 comments
Closed

cmd/go: cannot find module providing package error while go build #34985

qzyse2017 opened this issue Oct 18, 2019 · 11 comments

Comments

@qzyse2017
Copy link

@qzyse2017 qzyse2017 commented Oct 18, 2019

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

$ go version go1.12.6 linux/amd64

Does this issue reproduce with the latest release?

yes

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

NAME="openSUSE Leap"
VERSION="15.1 "
ID="opensuse-leap"

go env Output
$ go env

GOARCH="amd64"
GOBIN="/home/zyck/go/bin"
GOCACHE="/home/zyck/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/zyck/go"
GOPROXY="https://goproxy.io"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build270463791=/tmp/go-build -gno-record-gcc-switches"

What did you do?

make a new directory , testdir in home/zyck/go/src/
write a go file with code from https://github.com/PuerkitoBio/goquery#examples

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/PuerkitoBio/goquery"
)

func ExampleScrape() {
	// Request the HTML page.
	res, err := http.Get("http://metalsucks.net")
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()
	if res.StatusCode != 200 {
		log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
	}

	// Load the HTML document
	doc, err := goquery.NewDocumentFromReader(res.Body)
	if err != nil {
		log.Fatal(err)
	}

	// Find the review items
	doc.Find(".sidebar-reviews article .content-block").Each(func(i int, s *goquery.Selection) {
		// For each item found, get the band and title
		band := s.Find("a").Text()
		title := s.Find("i").Text()
		fmt.Printf("Review %d: %s - %s\n", i, band, title)
	})
}

func main() {
	ExampleScrape()
}

under testdir, run go build

What did you expect to see?

no output, the file build successfully

What did you see instead?

output:
build testdir cannot load github.com/PuerkitoBio/goquery: cannot find module providing package github.com/PuerkitoBio/goquery
no executable file generated

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Oct 18, 2019

The diagnostic messages for this sort of error are generally much clearer in Go 1.13. Please try Go 1.13.3 and see what you get.

@qzyse2017

This comment has been minimized.

Copy link
Author

@qzyse2017 qzyse2017 commented Oct 18, 2019

I remember it is like
module golang.org/x/net@.* found \(v0.0.0-.*\), but does not contain package golang.org/x/net

I found the above clause in the go repo while trying to find possible solutions, but this output does not seem to be mentioned in the issue area, so i tried a previous version,go1.12.6, and still could not work properly

Currently not have my laptop at hand, will provide the precise output later.

@qzyse2017

This comment has been minimized.

Copy link
Author

@qzyse2017 qzyse2017 commented Oct 18, 2019

The diagnostic messages for this sort of error are generally much clearer in Go 1.13. Please try Go 1.13.3 and see what you get.

it is

build testdir: cannot load github.com/PuerkitoBio/goquery: module github.com/PuerkitoBio/goquery@latest found (v1.5.0), but does not contain package github.com/PuerkitoBio/goquery

@qzyse2017

This comment has been minimized.

Copy link
Author

@qzyse2017 qzyse2017 commented Oct 18, 2019

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Oct 18, 2019

@qzyse2017, please provide more detail. The go env command says GOMOD="/dev/null", which implies (1) that you have GO111MODULE=on set explicitly, and (2) that you do not have a go.mod file.

But (2) implies that the error message should be go: cannot find main module; see 'go help modules', as shown below.

So it appears that your go env output does not match the go build directory, or perhaps you passed different arguments to go build?

$ cd $(go1.13.3 env GOPATH)

_gopath$ mkdir src/testdir

_gopath$ cd src/testdir/

_gopath/src/testdir$ cat > main.go
package main

import (
        "fmt"
        "log"
        "net/http"

        "github.com/PuerkitoBio/goquery"
)

func ExampleScrape() {
        // Request the HTML page.
        res, err := http.Get("http://metalsucks.net")
        if err != nil {
                log.Fatal(err)
        }
        defer res.Body.Close()
        if res.StatusCode != 200 {
                log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
        }

        // Load the HTML document
        doc, err := goquery.NewDocumentFromReader(res.Body)
        if err != nil {
                log.Fatal(err)
        }

        // Find the review items
        doc.Find(".sidebar-reviews article .content-block").Each(func(i int, s *goquery.Selection) {
                // For each item found, get the band and title
                band := s.Find("a").Text()
                title := s.Find("i").Text()
                fmt.Printf("Review %d: %s - %s\n", i, band, title)
        })
}

func main() {
        ExampleScrape()
}

_gopath/src/testdir$ GO111MODULE=on go1.13.3 build
go: cannot find main module; see 'go help modules'

_gopath/src/testdir$ go1.13.3 mod init testdir
go: creating new go.mod: module testdir

_gopath/src/testdir$ GO111MODULE=on go1.13.3 build
go: finding github.com/PuerkitoBio/goquery v1.5.0
go: downloading github.com/PuerkitoBio/goquery v1.5.0
go: extracting github.com/PuerkitoBio/goquery v1.5.0
go: downloading golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
go: downloading github.com/andybalholm/cascadia v1.0.0
go: extracting github.com/andybalholm/cascadia v1.0.0
go: extracting golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
go: finding github.com/andybalholm/cascadia v1.0.0
go: finding golang.org/x/net v0.0.0-20181114220301-adae6a3d119a

_gopath/src/testdir$ ls -l ./testdir
-rwxr-x--- 1 bcmills primarygroup 7734706 Oct 18 14:46 ./testdir

_gopath/src/testdir$
@qzyse2017

This comment has been minimized.

Copy link
Author

@qzyse2017 qzyse2017 commented Oct 19, 2019

sorry, i did not run go env in the same directory with go build,

when in the testdir directory, it is

GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/zyck/go/bin"
GOCACHE="/home/zyck/.cache/go-build"
GOENV="/home/zyck/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/zyck/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/zyck/go/src/testdir/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build139204416=/tmp/go-build -gno-record-gcc-switches"
@qzyse2017

This comment has been minimized.

Copy link
Author

@qzyse2017 qzyse2017 commented Oct 19, 2019

zyck@linux-3tzk:~/go/src/testdir> go build
build testdir: cannot load github.com/PuerkitoBio/goquery: module github.com/PuerkitoBio/goquery@latest found (v1.5.0), but does not contain package github.com/PuerkitoBio/goquery
zyck@linux-3tzk:~/go/src/testdir> ls
Dockerfile  go.mod  main.go

also tried building with docker image opensuse/leap:15.1, with go1.13.3, and it build successfully
the go env

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/usr/local/testapp/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=/tmp/go-build722608167=/tmp/go-build -gno-record-gcc-switches"
@qzyse2017

This comment has been minimized.

Copy link
Author

@qzyse2017 qzyse2017 commented Oct 19, 2019

some other info which may be helpful

zyck@linux-3tzk:~/go/src/testdir> go mod verify
all modules verified
zyck@linux-3tzk:~/go/src/testdir> go mod why
testdir imports
        github.com/PuerkitoBio/goquery: module github.com/PuerkitoBio/goquery@latest found (v1.5.0), but does not contain package github.com/PuerkitoBio/goquery
zyck@linux-3tzk:~/go/src/testdir> go mod download
zyck@linux-3tzk:~/go/src/testdir> go build
build testdir: cannot load github.com/PuerkitoBio/goquery: module github.com/PuerkitoBio/goquery@latest found (v1.5.0), but does not contain package github.com/PuerkitoBio/goquery
zyck@linux-3tzk:~/go/src/testdir> go mod download
zyck@linux-3tzk:~/go/src/testdir> ls ~/go/src/github.com/ | grep "Pue"
zyck@linux-3tzk:~/go/src/testdir> ls ~/go/pkg/mod/github.com/ | grep "Pue"
zyck@linux-3tzk:~/go/src/testdir> ls ~/go/pkg/mod/github.com/ | grep "pue"
!puerkito!bio
zyck@linux-3tzk:~/go/src/testdir> ls ~/go/src/github.com/ | grep "pue"
@qzyse2017

This comment has been minimized.

Copy link
Author

@qzyse2017 qzyse2017 commented Oct 21, 2019

try it in my another laptop with the same OS,the code build successfully

and

qizeyi@linux-bst3:~/personal/testdir> go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/qizeyi/.cache/go-build"
GOENV="/home/qizeyi/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/qizeyi/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/qizeyi/personal/testdir/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build388251140=/tmp/go-build -gno-record-gcc-switches"
@qzyse2017

This comment has been minimized.

Copy link
Author

@qzyse2017 qzyse2017 commented Oct 21, 2019

I finally get it work correctly by removing environment variable GOBIN, and remove pacakge !puerkito!bio, and run go build again, and it work correctly

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 21, 2019

Thanks for following up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.