We are trying to implement a grpc service in Node.
We have a common.proto
-file where we describe common messages, that we can reuse across different services.
Up until now, we have only implemented services in Go, and consumed them in either Go or PHP. This all works fine.
Now that we want to implement one service in Node, we have generated the pb.js-files, both from common.proto
, and lets call it service.proto
.
The problem is, that in service_pb.js
it generates the following code: require("../common_pb.js")
This is of course not valid, as the path to common_pb.js
is node_modules/@company/common-node/common_pb.js
, while now it looks for it in node_modules/@company/common-node/common_pb.js
.
I still have not been able to figure out how we can make this work correctly for Node, so if anyone has a solution that would be great.
Here is what we came up with as a solution:
The tree of the project looks like this:
root/
├─ common/
│ ├─ common.proto
├─ some-service/
│ ├─ some-service.proto
├─ other-service/
│ ├─ other-service.proto
If we in some-service.proto
needed a message definition from common.proto
we had import "common.proto";
and when running the project we included the common dir.
We changed this, so that we in the some-service.proto
file wrote common/common.proto
, and when running protoc
just included .
which is the root dir as shown in the tree above. That way the includes came out as require('../common/common_pb.js');
instead of require('../common_pb.js');
.