0
0

go: go.mod file not found in current directory or any parent directory; see 'go help modules'で怒られた

Posted at

go run . を実行すると以下のエラーで怒られた。

go: go.mod file not found in current directory or any parent directory; see 'go help modules'

調べてみるとgo modなるものが必要だったため以下のコマンドで追加。

$ go.mod hoge

$ cat go.mod
module hoge

go 1.22.3

module名とgo versionが記載されたファイルが追加された。

調べてみるとgo mod ファイルは go のパッケージの依存関係を管理するファイルのようだ。

$ go mod init hogehoge
go: \go.mod already exists

同一ディレクトリで再度実行すると怒られるので、1ディレクトリ1ファイルしか置けないようだ。
配下の別ディレクトリでは同名のmodファイルを作成することが出来た。

standard go project layoutを見る限り go.mod ファイルはプロジェクトルート配下に置くのがよいのかもしれない。

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