我在 main.go 中從非主包運行函數時遇到問題// main.gopackage mainimport test "./tests"func main() { test.Test("hello world")}// (relative to main.go) ./tests/test.gopackage testimport "fmt"func Test(str string) { fmt.Println(str)}輸出:build command-line-arguments: cannot find module for path _/c_/Users/Mike/Desktop/random/tests
1 回答

不負相思意
TA貢獻1777條經驗 獲得超10個贊
如果您使用的是 Go 1.16+,請使用 Go 模塊:
執行
go mod init projectname
替換為
import test "./tests"
import test "projectname/tests"
- 1 回答
- 0 關注
- 97 瀏覽
添加回答
舉報
0/150
提交
取消