LoginSignup
2
1

More than 3 years have passed since last update.

GoをHerokuにデプロイするときに Push rejected, failed to compile Go app. のエラー

Posted at

エラーについて

Goで作ったAPIをHerokuにデプロイしようと思い、
git push heroku main
コマンドをしたところ

!     Push rejected, failed to compile Go app.
!     Push failed

上のようなエラーで失敗。

解決した方法

ログを遡ってみると、

-----> 
 !!    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
 !!    
-----> New Go Version, clearing old cache

のような記述があった。最初はこれが原因だとは思っていなかったため放置していたのだが、試しに調べてみることにした。

調べてみると、Herokuでgoのバージョンを指定するには、go.modにて

go.mod
module xxxx

// +heroku goVersion go1.15      <--追加
go 1.15

のように記述する必要があるようだ。
書き直してpushしなおしてみると、無事デプロイできた。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1