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

1

6

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.

Minorite answered 20/5, 2020 at 19:24 Comment(0)
U
24

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)

Uncinus answered 13/6, 2020 at 2:5 Comment(1)
It works not well. After that I`ve got another exception: cmd/main.go:5:2: cannot find package "${GIT}/app/api" in any of: /usr/local/go/src/${GIT}/app/api (from $GOROOT) /go/src/${GIT}app/api (from $GOPATH) Conscious

© 2022 - 2024 — McMap. All rights reserved.