Unable to get the package from the module
Asked Answered
R

2

6

I am trying to create a microservice application, which depends on my net module which contains general errors (so i don't have to "replicate" them across all of my modules).

The issue is that for some reason it is able to find the module, but then telling me that the modules has no package (the net module does not have the main.go file, since it is just a group of files which are used across other projects)

go: finding github.com/USERNAME/net latest
build github.com/USERNAME/micro-helix: cannot load github.com/USERNAME/net: module github.com/USERNAME/net@latest found (v0.0.0-20191209010811-97a65ac0928c), but does not contain package github.com/USERNAME/net

And here is the go.mod file containing all the necessary requirements (as far as i am concerned):

module github.com/USERNAME/micro-helix

go 1.13

require (
    github.com/USERNAME/net v0.0.0-20191209010811-97a65ac0928c
    github.com/USERNAME/service v0.0.0-20191209005400-57ee0eb02082
    github.com/golang/protobuf v1.3.2
    github.com/hashicorp/consul/api v1.3.0 // indirect
    github.com/micro/go-micro v1.17.1
    github.com/micro/go-plugins v1.5.1 // indirect
    github.com/nats-io/nats-streaming-server v0.16.2 // indirect
    github.com/nats-io/stan.go v0.5.2 // indirect
    github.com/nicklaw5/helix v0.5.4
    github.com/spf13/viper v1.5.0 // indirect
)

The go.mod file for the net module is as simple as:

module github.com/USERNAME/net

go 1.13

If you need any further clarification, i am here to provide. I know that this might be some rookie mistake (misconfiguration) but this is my first week actually trying to write something in Go.

Update #1

This is the structure of the github.com/USERNAME/net module

/-
    errors/
        -   error.go            // github.com/USERNAME/net/errors
        -   code.go             // github.com/USERNAME/net/errors
    proto/
        -   error.pb.go         // github.com/USERNAME/net/proto
        -   response.pb.go      // github.com/USERNAME/net/proto
    errors.proto
    go.mod                      // module github.com/USERNAME/net
    response.proto
Ridgley answered 9/12, 2019 at 1:50 Comment(15)
What package name do the go files of module net declare?Cornetist
@BurakSerdar i have updated the question with the structure of the net module, i hope it helps, if not, could you please elaborate on your question as i am a bit confusedRidgley
How are you getting this error? Are you running go get? or did you import one of the packages in net, and running a go build?Cornetist
@BurakSerdar first of all, i've written the net module and pushed it to github, then i moved to the other application which is using the net, and i've installed it using the go get -u github.com/USERNAME/net, the thing is, second application is perfectly fine with importing the files (i can Shift + RClick on the file name in Goland and go the the net implementation), but the build fails with the error in the questionRidgley
I assume, errors.go has package errors. Do you import this as github.com/username/net/errors?Cornetist
@BurakSerdar yes, i do and yes, it is package errorsRidgley
Are you building this from an IDE, or using go build? If you're using an IDE, try go build.Cornetist
@BurakSerdar just tried that, still, same error even if i am using go buildRidgley
I'm stumped. Everything looks in order. I have similar setup that works. You sure everything you need is pushed to github? The errors points to go.mod declaring something different, or missing altogether.Cornetist
@BurakSerdar yep, just tried to create two pushes just to be sure, the "versioin" is changing as it should be, so i also have no ideaRidgley
version actually shouldn't be changing if you had everything up there. Did you check if github really has all your files?Cornetist
@BurakSerdar yes, i have been changing contents of the version.env file to see if i am actually getting latest version from the github and not the local cached oneRidgley
This is not in a private github repo is it? Maybe you can share the full url?Cornetist
@BurakSerdar it kind of is, since i am not the only one doing it and the person who shared the initial files might not want to share them. Just as an update, new project with replace in the go.mod works just fine, issue arises only when i am trying to load modules from gitRidgley
The error implies that somewhere you have an import "github.com/USERNAME/net", which isn't going to work since github.com/USERNAME/net contains no Go source files. I would search all your source for github.com/USERNAME/net and make sure you aren't trying to import that directly anywhere, that you're only importing packages under it.Sporophyll
H
4

Probably you've imported your module from some of *.go files in github.com/USERNAME/micro-helix as github.com/USERNAME/net.

You must import all of subpackages (which you use in that file) by there full paths like

import (
    "github.com/USERNAME/net/errors"
    "github.com/USERNAME/net/proto"
)
Harrisharrisburg answered 10/12, 2019 at 1:15 Comment(0)
E
0

I had a similar issue and the problem was that I had checked my code into master, but another branch was set as the default branch in the main git repo. Changing the default branch to master fixed it for me, but YMMV.

Eimile answered 3/2, 2020 at 18:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.