malformed module path … missing dot in first path element

旧巷老猫 提交于 2020-05-30 07:27:29

问题


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

My root's go.mod is like this

module prex-kyc

go 1.13

require ({requiredDependencies})

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 => ../

And in both validator's and server's main.go I do an import like this:

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

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.

I have tried building using go versions 1.12 and 1.13 and both windows 10 and Debian Linux.


回答1:


[SOLVED]

The issue was that i was importing utils like this:

import("prex-kyc/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



来源:https://stackoverflow.com/questions/59095179/malformed-module-path-missing-dot-in-first-path-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!