简体   繁体   中英

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.

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 )

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