5
4

【初学者】malformed module path "command-line-arguments": missing dot in first path elementの解決手順

Posted at

はじめに

お疲れさまです!
おおくまです!

こちらのコースのセクション13で、malformed module path "command-line-arguments": missing dot in first path elementというエラーが出ました!
その解決手順の備忘録です!

注意点

私はプログラミング学習中で、初学者です。
内容に誤りがある場合があります。
コメント等で教えていただけると幸甚です。

エラー内容

ディレクトリ構成
.
└ workspace
  └ golang_kisonyumon
    └ section13
      ├ foo
      │ └ foo.go
      └ main.go
main.go
package main

import (
	"command-line-arguments/Users/ryoyaokuma/workspace/golang_kisonyumon/section13/foo/foo.go"
	"fmt"
)

func main() {
	fmt.Println(foo.Max)
}
foo.go
package foo

const (
	Max = 100
	min = 1
)

func ReturnMin() int {
	return min
}
ターミナル
go run main.go

main.go:4:2: malformed module path "command-line-arguments": missing dot in first path element

エラーが出てしまいます!
main.go"command-line-arguments/Users/ryoyaokuma/workspace/golang_kisonyumon/section13/foo/foo.go"の部分があやしそうですね!

解決方法

ターミナル
go mod init example.com/section13

このコマンドを打つとgo.modファイルが作成されます!

go.mod
module example.com/section13

go 1.21.3

次にmain.goファイルを編集します!

main.go
package main

import (
	"fmt"
	"example.com/section13/foo"
)

func main() {
	fmt.Println(foo.Max)
}
ターミナル
go run main.go
100

無事に表示されればOKです!


最後まで読んでいただきありがとうございました!

5
4
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
5
4