build command-line-arguments: cannot find module for path と怒られた
GOPATH前提のハンズオンをやっててつまづいたところメモ
build command-line-arguments: cannot find module for path {{path/to/golang/dir}}
goのバージョンは go 1.17
import "./fuga"
と書いて go fmt hoge.go
なり go run hoge.go
をすると
build command-line-arguments: cannot find module for path {{path/to/golang/dir}}
と怒られた
結論は、 GO11MODULE=on
なのに早退パスを使ってたのが原因
ディレクトリが
hoge
|
ーfuga.go
hoge.go
% go mod init hoge
とした上で
import "hoge/fuga"
と書いたら解決した
ちなみに、最初はhoge/fugaディレクトリにも go.modを置いてたので
main.go:5:2: package hoge/fuga is not in GOROOT (/path/to/hoge/fuga)
な感じで怒られた
こちらを参照し、hogeだけにgo.modを置いたら解決した