Friday, January 13, 2017

Protobufjs unresolvable field type

If you got this error, one cause is there are many roots. Even if ecommerce.proto below imports the common.proto, protobufjs won't be able to resolve the message type if they are in different roots.

Instead of:

const common    = protobufjs.loadSync('common.proto');
const ecommerce = protobufjs.loadSync('ecommerce.proto');
const hr        = protobufjs.loadSync('hr.proto');


One solution:
const common = protobufjs.loadSync('common.proto');
protobufjs.loadSync('ecommerce.proto', common);
protobufjs.loadSync('hr.proto', common);

Another solution:
const root = protobufjs.loadSync([
    'common.proto', 
    'ecommerce.proto', 
    'hr.proto'
]);


Happy Coding!

No comments:

Post a Comment