简体   繁体   English

为什么这个 Go 构建在 Heroku 上失败? 它在本地构建没有问题

[英]Why is this Go build failing on Heroku? It builds locally with no issue

Is anyone able to tell me why this build has failed on heroku?有谁能告诉我为什么这个构建在 heroku 上失败了?

I've tried finding substitute packages and tidying the mod file, even deleting it and redoing it.我尝试过寻找替代包并整理 mod 文件,甚至删除并重做它。

here is my build log这是我的构建日志

    Overview Resources Deploy Metrics Activity Access Settings
Activity Feed  Build LogID f8e9d5ce-0d8f-4e8e-8b2a-661c4d1f68f7
-----> Building on the Heroku-20 stack
-----> Go app detected
-----> Fetching stdlib.sh.v8... done
-----> 
       Detected go modules via go.mod
-----> 
       Detected Module Name: github.com/xxxxxx/xxxxxx-xxxxxx
-----> 
 !!    The go.mod file for this project does not specify a Go version
 !!    
 !!    Defaulting to go1.12.17
 !!    
 !!    For more details see: https://devcenter.heroku.com/articles/go-apps-with-modules#build-configuration
 !!    
-----> Using go1.12.17
-----> Determining packages to install
       
       Detected the following main packages to install:
            github.com/xxxxxx/xxxxxx-xxxxxx
       
-----> Running: go install -v -tags heroku github.com/xxxxxx/xxxxxx-companion 
github.com/vektah/gqlparser/v2/ast
github.com/agnivade/levenshtein
github.com/mitchellh/mapstructure
github.com/vektah/gqlparser/v2/gqlerror
github.com/99designs/gqlgen/graphql
# github.com/99designs/gqlgen/graphql
../codon/tmp/cache/go-path/pkg/mod/github.com/99designs/gqlgen@v0.13.0/graphql/error.go:21:5: undefined: errors.As
github.com/99designs/gqlgen/graphql/errcode
github.com/vektah/gqlparser/v2/lexer
github.com/hashicorp/golang-lru/simplelru
github.com/vektah/gqlparser/v2/parser
github.com/hashicorp/golang-lru
github.com/gorilla/websocket
github.com/vektah/gqlparser/v2/validator
github.com/99designs/gqlgen/graphql/playground
github.com/xxxxxx/xxxxxx-xxxxxx/graph/model
github.com/xxxxxx/xxxxxx-xxxxxx/database
github.com/99designs/gqlgen/graphql/introspection
github.com/vektah/gqlparser/v2/validator/rules
github.com/go-sql-driver/mysql
github.com/vektah/gqlparser/v2
 !     Push rejected, failed to compile Go app.
 !     Push failed

Here is my go.mod file:这是我的 go.mod 文件:

module github.com/xxxxxx/xxxxxx-xxxxxx

go 1.15

require (
    github.com/99designs/gqlgen v0.13.0
    github.com/go-sql-driver/mysql v1.5.0
    github.com/hashicorp/golang-lru v0.5.1 // indirect
    github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238 // indirect
    github.com/stretchr/testify v1.5.1 // indirect
    github.com/vektah/gqlparser/v2 v2.1.0
    gopkg.in/yaml.v2 v2.2.8 // indirect
)

I'm at a complete loss, I suspect it has to do with an incorrect version, but the build log doesn't give me much to go on.我完全不知所措,我怀疑它与不正确的版本有关,但构建日志并没有给我太多关于 go 的信息。 How can I diagnose this kind of issue in the future?将来如何诊断此类问题?

Thank you.谢谢你。

Coming back to mark this one complete, I figured out that by specifying in the go mod file回来标记这个完成,我发现通过在 go mod 文件中指定

// +heroku goVersion go1.15 // +heroku goVersion go1.15

Go buildback supports arbitrary comments specifiying versioning before build. Go buildback 支持在构建之前指定版本控制的任意注释。

https://github.com/heroku/heroku-buildpack-go#go-module-specifics https://github.com/heroku/heroku-buildpack-go#go-module-specifics

Thank you as well to user @JimB for pointing me in the right direction.也感谢用户@JimB 为我指明了正确的方向。

You could add a directive // +heroku goVersion go1.15 in your go.mod file.您可以在go.mod文件中添加指令// +heroku goVersion go1.15

module somemodule

// +heroku goVersion go1.15
go 1.15

require (
    // ...
)

Then it should look like this.然后它应该看起来像这样。

remote:        Detected go modules via go.mod
remote: ----->
remote:        Detected Module Name: somemodule
remote: ----->
remote: -----> New Go Version, clearing old cache
remote: -----> Installing go1.15

Documentation: https://github.com/heroku/heroku-buildpack-go#go-module-specifics文档: https://github.com/heroku/heroku-buildpack-go#go-module-specifics

Go Module Specifics Go 模块规格

You can specify specific package spec(s) via the go.mod file's // +heroku install directive (see below).您可以通过go.mod文件的// +heroku install指令指定特定的 package 规范(见下文)。

// +heroku goVersion <version> : the major version of go you would like Heroku to use when compiling your code. // +heroku goVersion <version> : go 的主要版本,您希望在编译代码时使用 Heroku。 If not specified this defaults to the buildpack's [DefaultVersion].如果未指定,则默认为 buildpack 的 [DefaultVersion]。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM