格式错误的模块路径...第一个路径元素中缺少点 [英] malformed module path ... missing dot in first path element
问题描述
我有一个包含2个不同可执行文件的项目,每个可执行文件都有自己的依赖项以及对根目录的共享依赖项,如下所示:
I have a project with 2 different executables, each having it's own dependencies plus a shared dependency on the root, something like this:
Root
|->server
| |-> main.go
| |-> someOtherFiles.go
| |-> go.mod
| |-> go.sum
|->validator
| |-> main.go
| |-> someOtherFiles.go
| |-> go.mod
| |-> go.sum
|->utils
| |-> someOtherFiles.go
|->config
| |-> someOtherFiles.go
|-> go.mod
|-> go.sum
我的根目录go.mod就是这样
My root's go.mod is like this
module prex-kyc
go 1.13
require ({requiredDependencies})
我的验证者的go.mod就是这样(服务器是模拟的)
And my validator's go.mod is like this (server's is analogue)
module validator
go 1.13
require (
prex-kyc v0.0.0-00010101000000-000000000000
{otherRequiredDependencies}
)
replace prex-kyc => ../
在验证者和服务器的main.go中,我都这样输入:
And in both validator's and server's main.go I do an import like this:
import (
"prex-kyc/utils"
{someOtherImports}
)
当我尝试构建其中一个项目时,出现此错误:build validator: cannot load prex-kyc/config: malformed module path "prex-kyc/config": missing dot in first path element
When I try to build either one of the projects i get this error: build validator: cannot load prex-kyc/config: malformed module path "prex-kyc/config": missing dot in first path element
我知道代码没有错,因为它可以在其他人的环境中进行编译.
I know there's nothing wrong with the code because it can be compiled in someone else's environment.
我曾尝试使用1.12和1.13版本以及Windows 10和Debian Linux进行构建.
I have tried building using go versions 1.12 and 1.13 and both windows 10 and Debian Linux.
推荐答案
[已解决]
问题是我正在这样导入utils:
The issue was that i was importing utils like this:
import("prex-kyc/utils")
但是实际上prex-kyc模块中没有软件包utils(仅目录utils),并且该目录中的每个.go文件都有不同的软件包名称.通过将其中每个更改为"package utils",此问题得以解决.
But actually there was no package utils inside module prex-kyc, (only directory utils) and every .go files in that directory had a different package name. By changing each one of them to "package utils" the issue was solved.
错误在第一个路径元素中缺少点"确实令人误解
The error "missing dot in first path element" was really misleading though
这篇关于格式错误的模块路径...第一个路径元素中缺少点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!