4

我有一个项目,其中包含 2 个不同的可执行文件,每个都有自己的依赖项以及对根目录的共享依赖项,如下所示:

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

我的root的go.mod是这样的

module prex-kyc

go 1.13

require ({requiredDependencies})

我的验证器 go.mod 是这样的(服务器是模拟的)

module validator

go 1.13

require (
    prex-kyc v0.0.0-00010101000000-000000000000
    {otherRequiredDependencies}
)

replace prex-kyc => ../

在验证器和服务器的 main.go 中,我执行如下导入:

import (
    "prex-kyc/utils"
    {someOtherImports}
)

当我尝试构建其中一个项目时,我收到此错误:build validator: cannot load prex-kyc/config: malformed module path "prex-kyc/config": missing dot in first path element

我知道代码没有问题,因为它可以在其他人的环境中编译。

我尝试使用 go 版本 1.12 和 1.13 以及 Windows 10 和 Debian Linux 进行构建。

4

1 回答 1

4

[解决了]

问题是我正在像这样导入实用程序:

import("prex-kyc/utils")

但实际上模块 prex-kyc 中没有包 utils(只有目录 utils),并且该目录中的每个 .go 文件都有不同的包名。通过将它们中的每一个更改为“package utils”,问题就解决了。

错误“第一个路径元素中缺少点”确实具有误导性

于 2019-12-03T20:09:26.170 回答