LoginSignup
2
0

More than 1 year has passed since last update.

go: cannot find main module, but found|GolangのテストをGitHub Actionsで回した時のエラー

Posted at

 状況

ある書籍のサンプルコードを動かしていたところ遭遇したエラーです。
Golangは触ったこともない状態で進めていたのでモジュールやGoPathなども
理解できていない状態でした。

エラーメッセージ

GitHub ActionsでGolangのテストファイルを実行した時に出たエラーです。

error.go

go: cannot find main module, but found .git/config in /__w/app-name/app-name
    to create a module there, run:
    go mod init
Error: Process completed with exit code 1.

原因

go.modファイルがないことでした。
詳しい原因知っている方いましたらコメントいただけたら嬉しいです。

解決方法

以下のコマンドでgo.modファイルをプロジェクトディレクトリのルートに生成しpushしたらエラーが消えました。

go.sh

$ go mod init github.com/example/go-app-name

2
0
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
0