Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang cannot find module providing package {PACKAGE_NAME}: working directory is not part of a module

I am wondering what is going on with my local build? I want to test deployment to DEV to fix problem, but I can’t build. make build-mac

env GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.version=v1.0.20-16-ga0298c0 -X main.commit=a0298c0 -X main.branch=master -X main.buildDate=2020-05-20T11:12:36-0700" -o backend main.go
main.go:7:2: cannot find module providing package github.com/LF-Engineering/vulnerability-detection/backend/cmd: working directory is not part of a module
main.go:8:2: cannot find module providing package github.com/LF-Engineering/vulnerability-detection/backend/v2: working directory is not part of a module
make: *** [build-mac] Error 1

Same with building the lambda:

dep ensure -v
Building a staticlly linked binary...
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=v1.0.20-16-ga0298c0 -X main.commit=a0298c0 -X main.branch=master -X main.buildDate=2020-05-20T11:26:15-0700" -tags aws_lambda -o backend_aws_lambda main.go
main.go:7:2: cannot find module providing package github.com/LF-Engineering/vulnerability-detection/backend/cmd: working directory is not part of a module
main.go:8:2: cannot find module providing package github.com/LF-Engineering/vulnerability-detection/backend/v2: working directory is not part of a module
make: *** [build_aws_lambda] Error 1```

I have done a clean build, removed vendor and re-tried.
Wonder if this is a go version problem? Recently updated:
```go version             
go version go1.14.3 darwin/amd64

It would be nice to resolve the odd issue related to the package setup and vendor/Gopkg.toml/lock being in the parent folder. we should use go mod as this is going to be the standard moving forward just, I had trouble using it with the directory structure for some reason.

like image 944
Awesome Infinity Avatar asked May 20 '20 19:05

Awesome Infinity


People also ask

How do I fix missing go sum entry for module providing package?

You should be able to fix that case by running go mod tidy (with either Go 1.15. 8 or Go 1.16), or by setting -mod=mod explicitly (perhaps as GOFLAGS=-mod=mod ).

Is Go mod mandatory?

A go. mod file is required for the main module, and for any replacement module specified with a local file path. However, a module that lacks an explicit go. mod file may still be required as a dependency, or used as a replacement specified with a module path and version; see Compatibility with non-module repositories.

How do I update go modules?

You can upgrade or downgrade a dependency module by using Go tools to discover available versions, then add a different version as a dependency. To discover new versions use the go list command as described in Discovering available updates.

What is module in Golang?

Go modules commonly consist of one project or library and contain a collection of Go packages that are then released together. Go modules solve many problems with GOPATH , the original system, by allowing users to put their project code in their chosen directory and specify versions of dependencies for each module.


1 Answers

I found the same issue before, and I sovled this issue, change environment variables, GO111MODULE from on to auto

Open up File/Preferences/Settings and search for “go tools env vars” Click “Edit in settings.json” and set GO111MODULE to auto (instructions from https://dev.to/codeboten/disabling-go-modules-in-visual-studio-code-31mp)

like image 79
timmy_cai Avatar answered Nov 15 '22 06:11

timmy_cai