grpc proto-loader: trouble loading a proto that imports other protos
Hi folks,
I'm running into an issue with loadSync from the grpc/proto-loader package where imports are looking for nested paths instead of from the top of the included directories.
The protos are in a package that has a structure like the following:
@packagename/protos
- lib
- - grpc_clients
- - - namespace
- - - - teams
- - - - - teamA
- - - - - - teamA.proto
- - - - - - teamA.js
- - - - - teamB
- - - - - - teamB.proto
- - - - - - teamB.js
- - - google
- - - - ... several google protos
the teamA.proto uses teamB.proto via import "namespace/teams/teamB/teamB.proto
I am trying to get the package definition for teamA by running the following:
loadSync('namespace/teams/teamA/teamA.proto', {
includeDirs: ['path/to/node_modules/@packagename/protos/lib/grpc_clients'],
keepCase: true,
objects: true,
arrays: true,
defaults: true,
enums: String
});
It is finding the proto properly but when teamA imports teamB it's trying to do it relative to the teamA folder instead of the path/to/node_modules/@packagename/protos/lib/grpc_clients folder.
Ex.
Error: ENOENT: no such file or directory, open '/Users/wenincode/Development/app/node_modules/@packagename/protos/lib/grpc_clients/namespace/teams/teamA/namespace/teams/teamB/teamB.proto'
Is there a way for me to have it base imports off of the includeDirs? Or perhaps I'm missing something obvious here.
It sounded somewhat similar to this issue, but that repro repo doesn't exist anymore.
Apologies for the lack of repro repo. The package of grpc clients I'm consuming is internal. Figured it wouldn't hurt to ask anyway!
It does import relative to the includeDirs, that's the purpose of that option. The error message you're seeing is a bit misleading, because after it tries to load the file from the includeDirs, it falls back to the default behavior of searching relative to the including file, as you see there. There should also be a warning indicating that it failed to load from the includeDirs.
As mentioned in the issue you linked to, includeDirs should be an absolute path, so make sure that is the case with yours.
Ah! yes, updating it to use absolute path. Seeing it now has the warning that the proto isn't in that folder and it is indeed missing. Which is an issue with our package. Appreciate the help.