Go: cannot find module providing package

Created on 23 Nov 2018  ยท  12Comments  ยท  Source: golang/go

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

$ go version
go version go1.11.2 windows/amd64

Does this issue reproduce with the latest release?

Yes

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\212326985\AppData\Localgo-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Drive\Programminggo
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Gopkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
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 -fmessage-length=0 -fdebug-prefix-map=C:Users\212326~1\AppData\Local\Tempgo-build644952330=/tmp/go-build -gno-record-gcc-switches

What did you do?

I have files with the following contents

messaging.go

package messaging

import (
    "github.com/aws/aws-sdk-go/service/sqs/sqsiface"
    "strings"
)

// Listener is the interface that defines what the listener can do
type Listener interface {
    Listen()
}

type SQSConfig struct {

}

// NewSQSListener is the factory function using which we can create different types of listeners
func NewSQSListener(svc sqsiface.SQSAPI, cfg *SQSConfig) (Listener) {
        return &sqsListener{svc: svc}
}

type sqsListener struct {
    svc sqsiface.SQSAPI
    cfg SQSConfig
}

func (l *sqsListener) Listen() {
    // sqsiface.SQSAPI
}

and

main.go

package main

import (
    "github.com/aws/aws-sdk-go/service/sqs"
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"

    "github.enterpriseurl.com/user/tesla/pkg/messaging"
)

func main() {
    sess := session.Must(session.NewSessionWithOptions(session.Options{
        SharedConfigState: session.SharedConfigEnable,
    }))

    svc := sqs.New(sess)
    l := messaging.NewSQSListener(svc, nil)
    l.Listen()
}

When I run go build, I get the following error

..\..\go\pkg\mod\github.com\aws\[email protected]\aws\credentials\shared_credentials_provider.go:8:2: unknown import path "github.com/aws/aws-sdk-go/internal/ini": cannot find module providing package github.com/aws/aws-sdk-go/internal/ini
..\..\go\pkg\mod\github.com\aws\[email protected]\aws\types.go:7:2: unknown import path "github.com/aws/aws-sdk-go/internal/sdkio": cannot find module providing package github.com/aws/aws-sdk-go/internal/sdkio
..\..\go\pkg\mod\github.com\aws\[email protected]\aws\client\default_retryer.go:8:2: unknown import path "github.com/aws/aws-sdk-go/internal/sdkrand": cannot find module providing package github.com/aws/aws-sdk-go/internal/sdkrand
..\..\go\pkg\mod\github.com\aws\[email protected]\aws\ec2metadata\api.go:12:2: unknown import path "github.com/aws/aws-sdk-go/internal/sdkuri": cannot find module providing package github.com/aws/aws-sdk-go/internal/sdkuri
..\..\go\pkg\mod\github.com\aws\[email protected]\aws\credentials\shared_credentials_provider.go:9:2: unknown import path "github.com/aws/aws-sdk-go/internal/shareddefaults": cannot find module providing package github.com/aws/aws-sdk-go/internal/shareddefaults
main.go:6:2: unknown import path "github.com/aws/aws-sdk-go/service/sqs": cannot find module providing package github.com/aws/aws-sdk-go/service/sqs
pkg\messaging\messaging.go:4:2: unknown import path "github.com/aws/aws-sdk-go/service/sqs/sqsiface": cannot find module providing package github.com/aws/aws-sdk-go/service/sqs/sqsiface
..\..\go\pkg\mod\github.com\aws\[email protected]\aws\credentials\stscreds\assume_role_provider.go:89:2: unknown import path "github.com/aws/aws-sdk-go/service/sts": cannot find module providing package github.com/aws/aws-sdk-go/service/sts

What did you expect to see?

I expected the project to build

What did you see instead?

I saw the error mentioned above

WaitingForInfo modules

Most helpful comment

It occurs when you did go mod init and renamed your project after.
I had the same @alwindoss.

I just removed modules from project and did go mod init and go mod vendor again.

All 12 comments

@alwindoss I'm fairly certain there's no bug here, because, modulo fixing a few issues with your repro above, this works for me:

$ cd $(mktemp -d)
$ go mod init github.enterpriseurl.com/user/tesla/pkg
go: creating new go.mod: module github.enterpriseurl.com/user/tesla/pkg
$ cat <<EOD >main.go
package main

import (
        "github.com/aws/aws-sdk-go/aws/session"
        "github.com/aws/aws-sdk-go/service/sqs"

        "github.enterpriseurl.com/user/tesla/pkg/messaging"
)

func main() {
        sess := session.Must(session.NewSessionWithOptions(session.Options{
                SharedConfigState: session.SharedConfigEnable,
        }))

        svc := sqs.New(sess)
        l := messaging.NewSQSListener(svc, nil)
        l.Listen()
}
EOD
$ mkdir messaging
$ cat <<EOD >messaging/messaging.go
package messaging

import (
        "github.com/aws/aws-sdk-go/service/sqs/sqsiface"
)

// Listener is the interface that defines what the listener can do
type Listener interface {
        Listen()
}

type SQSConfig struct {
}

// NewSQSListener is the factory function using which we can create different types of listeners
func NewSQSListener(svc sqsiface.SQSAPI, cfg *SQSConfig) Listener {
        return &sqsListener{svc: svc}
}

type sqsListener struct {
        svc sqsiface.SQSAPI
        cfg SQSConfig
}

func (l *sqsListener) Listen() {
        // sqsiface.SQSAPI
}
EOD
$ go build
go: finding github.com/aws/aws-sdk-go/service/sqs latest
go: finding github.com/aws/aws-sdk-go/aws/session latest
go: finding github.com/aws/aws-sdk-go/service/sqs/sqsiface latest
go: finding github.com/aws/aws-sdk-go/service latest
go: finding github.com/aws/aws-sdk-go v1.15.81
go: finding github.com/aws/aws-sdk-go/aws latest
go: downloading github.com/aws/aws-sdk-go v1.15.81
go: finding github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8
go: downloading github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8
$ cat go.mod
module github.enterpriseurl.com/user/tesla/pkg

require github.com/aws/aws-sdk-go v1.15.81

Can I therefore suggest we move the discussion to another forum? https://github.com/golang/go/wiki/Questions

Are you saying if I have a package within my project I need to create a module out of it else I will not be able to use it from within my project?

No. A module is a collection of packages. In the example above, I created a "dummy" module github.enterpriseurl.com/user/tesla/pkg that contains two packages:

  • github.enterpriseurl.com/user/tesla/pkg - the main package
  • github.enterpriseurl.com/user/tesla/pkg/messaging - the messaging package

As I mentioned above, please let's move discussion to another forum: https://github.com/golang/go/wiki/Questions

Also to make sure you are aware of the modules wiki: https://github.com/golang/go/wiki/Modules

@myitcv This issue is not resolved. Let's not hurriedly close issues until it really is.

You are making some assumptions here:

  1. That I do not have a go.mod file. Truth is I do have it and I have listed the contents of it below
  2. I am not sure why you are doing a go mod init github.enterpriseurl.com/user/tesla/pkg. The root of my project is tesla and I can confirm that it has a go.mod file and following is the content

go.mod file

module github.enterpriseurl.com/user/tesla

require github.com/aws/aws-sdk-go v1.15.81

Following is my project structure:

tesla/main.go
tesla/go.mod
tesla/go.sum
tesla/pkg/messaging/messaging.go

As far as I am concerned this is still an issue. Request you to please reopen this issue. If you have any questions please ask I am more than happy to answer them.

PS: if I copy this project structure into the $GOPATH/src/github.enterpriseurl.com/user/tesla the same project builds without any issue using go build

@alwindoss

Let's not hurriedly close issues until it really is.

I closed the issue because I don't see an issue here, and included a full reproduction https://github.com/golang/go/issues/28928#issuecomment-441252752 to illustrate that.

  1. That I do not have a go.mod file. Truth is I do have it and I have listed the contents of it below
  2. am not sure why you are doing a go mod init github.enterpriseurl.com/user/tesla/pkg. The root of my project is tesla and I can confirm that it has a go.mod file and following is the content

No, I wasn't assuming you don't have a go.mod. My use of go mod init is included as part of my full reproduction. The actual module path is not significant in this case, but for completeness, I have modified the reproduction below.

As a next step, please can you try the steps below (at least the Windows equivalent commands) and include a full log of the commands and their output?

$ export GOPATH=$(mktemp -d)
$ cd $(mktemp -d)
$ go mod init github.enterpriseurl.com/user/tesla
go: creating new go.mod: module github.enterpriseurl.com/user/tesla
$ cat <<EOD >main.go
package main

import (
        "github.com/aws/aws-sdk-go/aws/session"
        "github.com/aws/aws-sdk-go/service/sqs"

        "github.enterpriseurl.com/user/tesla/pkg/messaging"
)

func main() {
        sess := session.Must(session.NewSessionWithOptions(session.Options{
                SharedConfigState: session.SharedConfigEnable,
        }))

        svc := sqs.New(sess)
        l := messaging.NewSQSListener(svc, nil)
        l.Listen()
}
EOD
$ mkdir -p pkg/messaging
$ cat <<EOD >pkg/messaging/messaging.go
package messaging

import (
        "github.com/aws/aws-sdk-go/service/sqs/sqsiface"
)

// Listener is the interface that defines what the listener can do
type Listener interface {
        Listen()
}

type SQSConfig struct {
}

// NewSQSListener is the factory function using which we can create different types of listeners
func NewSQSListener(svc sqsiface.SQSAPI, cfg *SQSConfig) Listener {
        return &sqsListener{svc: svc}
}

type sqsListener struct {
        svc sqsiface.SQSAPI
        cfg SQSConfig
}

func (l *sqsListener) Listen() {
        // sqsiface.SQSAPI
}
EOD
$ tree --noreport
.
|-- go.mod
|-- main.go
`-- pkg
    `-- messaging
        `-- messaging.go
$ go build
go: finding github.com/aws/aws-sdk-go/service/sqs/sqsiface latest
go: finding github.com/aws/aws-sdk-go/service/sqs latest
go: finding github.com/aws/aws-sdk-go/aws/session latest
go: finding github.com/aws/aws-sdk-go/service latest
go: finding github.com/aws/aws-sdk-go/aws latest
go: finding github.com/aws/aws-sdk-go v1.15.82
go: downloading github.com/aws/aws-sdk-go v1.15.82
go: finding github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8
go: downloading github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8
$ cat go.mod
module github.enterpriseurl.com/user/tesla

require github.com/aws/aws-sdk-go v1.15.82

@myitcv I don't know how to explain this, what did not work last night for me apparently is working now. I have not made any changes to the code but when I ran go build it is successfully building now.

If for some reason I am able to replicate it I will add the details here.

Thanks. Feel free to reopen along with the full log if you encounter the issue again.

It occurs when you did go mod init and renamed your project after.
I had the same @alwindoss.

I just removed modules from project and did go mod init and go mod vendor again.

This issue occurred to me today - with go 1.12 . The error was due to an old emacs fly-check version meddling with go vet.

Reinstalling latest emacs plugins by deleting ~/.emacs.d/elpa folder resolved the issue.

Why does this error occur when I set

GOPROXY=file:///home/tetravalence/Workspace/src

to my local repository to do some private development work?

It occurred for me because my top level go.mod directory had no go files

โ”œโ”€โ”€ go.mod
โ”œโ”€โ”€ go.sum
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ server
    โ”œโ”€โ”€ api
    โ”‚ย ย  โ”œโ”€โ”€ api.go
     ...
module github.com/exampler/example

go 1.15

It was fixed after I added a go file something.go in the directory containing the go.mod file with package example
It took me 3-4 hrs to realize this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chai2010 picture chai2010  ยท  216Comments

bradfitz picture bradfitz  ยท  151Comments

jessfraz picture jessfraz  ยท  154Comments

ianlancetaylor picture ianlancetaylor  ยท  519Comments

ianlancetaylor picture ianlancetaylor  ยท  138Comments