5

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Juan Marín
  • 91
  • 1
  • 2
  • 5
  • 1
    does this help ? https://stackoverflow.com/a/58563894/4466350 –  Nov 28 '19 at 20:27
  • It didn't, I've tried several module names and how to reference it, always get the same error. – Juan Marín Nov 28 '19 at 20:52
  • Can you please confirm that there is no go.mod file in the utils folder? As you don't mention one I'm assuming its not there but my mockup of your issue compiles without error; however if I add a go.mod into the utils folder then I get the same error. – Brits Nov 29 '19 at 03:50
  • Brits, That's right, there is no go.mod file in the utils folder – Juan Marín Dec 02 '19 at 12:54

1 Answers1

4

[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

Juan Marín
  • 91
  • 1
  • 2
  • 5