简体   繁体   中英

No required module provides package after running go get

So I have a GOPATH set to my working directory and I create a new script file.go. In that script I use I import "github.com/..." I ran 'go get github.com/... and it appeared to download but when running go run file.go I still get: no required module provides package github.com/gordonklaus/portaudio: go.mod file not found in current directory or any parent directory; see 'go help modules' no required module provides package github.com/gordonklaus/portaudio: go.mod file not found in current directory or any parent directory; see 'go help modules' .

I tried adding go.mod but then the error just changes to:

go: no module declaration in go.mod. To specify the module path:
        go mod edit -module=example.com/mod

So I adding the following to my go.mod file and it looks like this now:

module MyModuleName

go 1.17

require(
    "github.com/..." v1.2.3
)

But I get:

missing go.sum entry for module providing package github.com/...; to add:
        go mod download github.com/...

But when I run go mod download github.com/... I get:

github.com/...@v1.2.3: invalid version: unknown revision v1.2.3

So I don't know what todo from here.

I would:

  • edit go.mod and remove the line where v1.2.3 is
  • go get github.com/gordonklaus/portaudi (executed in the project folder, where go.mod is)
  • go mod tidy

The end result should be the library added with a tag matching its latest release.

If someone having similar error:

go: no module declaration in go.mod. To specify the module path:
    go mod edit -module=example.com/mod

while trying to run some go code like go run test.go , the following helped me to eliminate the error:

GO111MODULE=on go run test.go 

After that I was able to run go code normally, without specifying GO111MODULE variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM