Golang找不到提供软件包{PACKAGE_NAME}的模块:工作目录不是模块的一部分 [英] Golang cannot find module providing package {PACKAGE_NAME}: working directory is not part of a module

查看:93
本文介绍了Golang找不到提供软件包{PACKAGE_NAME}的模块:工作目录不是模块的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道本地构建怎么了?我想测试到DEV的部署以解决问题,但无法构建.制作build-mac

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

与构建lambda相同:

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

最好解决与父文件夹中的程序包设置和vendor/Gopkg.toml/lock相关的奇怪问题.我们应该使用go mod,因为这将成为前进的标准只是,由于某种原因,我无法在目录结构中使用它.

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.

推荐答案

我之前发现了相同的问题,所以解决了这个问题,从 on 更改了环境变量 GO111MODULE >转到 auto

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

打开文件/首选项/设置并搜索"go tools env vars"单击在settings.json中编辑",然后将GO111MODULE设置为 auto (来自 https://dev.to/codeboten/disabling-go-modules-in-visual-studio-code-31mp )

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)

这篇关于Golang找不到提供软件包{PACKAGE_NAME}的模块:工作目录不是模块的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆