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

Issue

Is anyone able to tell me why this build has failed on heroku?

I’ve tried finding substitute packages and tidying the mod file, even deleting it and redoing it.

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:

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. How can I diagnose this kind of issue in the future?

Thank you.

Solution

You could add a directive // +heroku goVersion go1.15 in your go.mod file.

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

Go Module Specifics

You can specify specific package spec(s) via the go.mod file’s // +heroku install directive (see below).

// +heroku goVersion <version>: the major version of go you would
like Heroku to use when compiling your code. If not specified this
defaults to the buildpack’s [DefaultVersion].

Answered By – Coconut

Answer Checked By – Clifford M. (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.