17

I have created following .proto file in the path: microservice/internal/proto-files/domain/repository.proto

syntax = "proto3";

package domain;

option go_package = "microservice/internal/gRPC/domain";

message Repository {
  int64 id  = 1;
  string name = 2;
  int64 userId = 3;
  bool isPrivate = 4;
}

and also following .proto file in another path: microservice/internal/proto-files/service

syntax = "proto3";

package service;

option go_package = "microservice/internal/gRPC/service";

import "microservice/internal/proto-files/domain/repository.proto";

//RepositoryService Definition
service RepositoryService {
  rpc add (domain.Repository) returns (AddRepositoryResponse);
}

message AddRepositoryResponse {
  domain.Repository addedRepository = 1;
  Error error = 2;
}
message Error {
  string code = 1;
  string message = 2;
}

but my IDE(goland) cannot resolve import in repository-service.proto and also when I use protoc command to generate .pb.go file, I will face following error:

microservice/internal/proto-files/domain/repository.proto: File not found.
ttrasn
  • 4,322
  • 4
  • 26
  • 43
Siavoosh
  • 181
  • 1
  • 1
  • 5

2 Answers2

43

First of all, your import path is better to be like this :

import "domain/repository.proto";

You must add the path of your proto files to your Goland. for that you must go to setting > Languages & Frameworks > Protocol Buffers then uncheck Configure automatically.

After that add this path on import paths.

microservice/internal/proto-files

like this : enter image description here

ttrasn
  • 4,322
  • 4
  • 26
  • 43
  • 2
    unfortunately not fixed by this. – Siavoosh Aug 21 '20 at 17:30
  • @Siavoosh also add this line `microservice/internal/gRPC` – ttrasn Aug 21 '20 at 17:31
  • I moved my project to ~GOPATH/src and added ~/GOPATH/src to the configuration path and error has been moved, but still I'm looking for a way to fix it in case I have my project out of GOPATH and using go-mod – Siavoosh Aug 21 '20 at 18:06
  • @Siavoosh I updated my answer. I think problem is on your import path. – ttrasn Aug 21 '20 at 18:07
  • even by changing the import path its not resolved. still I'm looking for a way to get rid of this error(cannot resolve '...') while I'm using gomod. – Siavoosh Aug 22 '20 at 13:32
  • 1
    This works except I selected the root folder that holds all my Proto files. Example, if I have `project/proto/thing/v1/thing.proto`, I would do the above steps but add `project/proto` to the configuration. Then you can import with `import "thing/v1/thing.proto"`. Then reference it in your message like so `this.v1.` where message is item you want to import, eg `Thing` – Ari Jun 26 '21 at 13:07
  • This issue should not be closed https://github.com/jvolkman/intellij-protobuf-editor/issues/33 – Ghilteras Sep 07 '21 at 20:07
  • My compiler warning was gone with this but build is still failing with error, i can click on import to go to the file all that is working but build is failing still with same error, unable to find file on the path – Cyph3rCod3r Sep 01 '22 at 16:12
  • @Dr.aNdRO The problem is in your proto generator command, please check it – ttrasn Sep 01 '22 at 16:24
1

I have the same problem; when I use "implort domail/file-name.proto" statements, the IDE gives me the error message: Cannot resolve import 'domain/file-name.proto"

Finally I found my problem: The parent folder was not marked as "Resources Root", so I marked it and that solved my problem.

ide with the problem

Dave Arkell
  • 3,920
  • 2
  • 22
  • 27
Hongantong
  • 31
  • 1