duanna5749 2019-04-13 04:55
浏览 1696
已采纳

收到错误:构建Go项目时,“ build flag -mod = vendor仅在使用模块时有效”

According to this document I need to add -mod=vendor to my build command to make use of my local vendor folder:

By default, go commands like go build ignore the vendor directory when in module mode. The -mod=vendor flag (e.g., go build -mod=vendor) instructs the go commands to use the main module's top-level vendor directory to satisfy dependencies.

When I run this command:

go build -mod=vendor -a -ldflags "-s -w -X github.com/my-api/pkg/config.Version=169.3988801" -o bin/my-api

I get this error:

build flag -mod=vendor only valid when using modules

Locally the command works as expected, the error only occurs on the build server.

  • 写回答

1条回答 默认 最新

  • doudou_3636 2019-04-13 18:17
    关注

    I think the key part of the help you are showing is when in module mode. This will only happen when you are working on code outside of GOPATH or if you have set the GO111MODULE=on environment variable so I think you have this set in your local environment but not the build server.

    More information about enabling module support is here:

    https://golang.org/cmd/go/#hdr-Preliminary_module_support

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?