我在 root/src/abc
中有 go.mod
文件。在 root/build-scripts
中,我有一个执行 go get
的脚本。因为我使用的是 Go 1.11,所以我没有使用 go 路径,而是 root/src/abc
中的 mod 文件负责其他导入,但构建脚本中使用的包会出错:
go: cannot determine module path for source directory.
有什么建议吗?
最佳答案
如果没有看到您运行的实际命令,很难确定地说什么,因为您的脚本似乎不会更改工作目录,因此它们执行的 go
命令不在模块的根目录中文件夹或其任何子文件夹。
引自Command Go: The go.mod file:
A module version is defined by a tree of source files, with a go.mod file in its root. When the go command is run, it looks in the current directory and then successive parent directories to find the go.mod marking the root of the main (current) module.
因此您的脚本应该将工作目录更改为 root/src/abc
或其任何子文件夹,否则 go 命令将找不到 go.mod
文件。
关于go - 无法确定源目录的模块路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52978070/