YoshiyukiKato / grpc-mock

A simple mock gRPC server on Node.js
MIT License
85 stars 24 forks source link

Error: unresolvable extensions: 'extend google.protobuf.FieldOptions' when running server.js #17

Open SachinHg opened 5 years ago

SachinHg commented 5 years ago

Hi, I have a proto file which uses google.protobuf.FieldOptions and it fails compailing that protobufjs cannot resolve this. Pasted the error below: /node_modules/protobufjs/src/root.js:243 throw Error("unresolvable extensions: " + this.deferred.map(function(field) { Any idea how to make protobufjs support this? Thanks

jkryl commented 4 years ago

I had the same problem and needed the following workaround to make it work. When loading the proto file you need to specify include file with definition of FieldOptions. This works assuming that protobufjs is a dependency of your project and that your script is in top-level directory of your project.

const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: false,
  longs: Number,
  enums: String,
  defaults: true,
  oneofs: true,
  // this is to load google/descriptor.proto, otherwise you would see error:
  // unresolvable extensions: 'extend google.protobuf.FieldOptions' in .csi.v1
  includeDirs: [__dirname + '/node_modules/protobufjs'],
});

Also it's not a defect in grpc-mock package as this error appears anytime loading a proto file with such definition.

tajpouria commented 3 years ago
import { status } from "grpc";
import { createMockServer } from "./grpc-mock";

const mockServer = createMockServer({
  protoPath: "proto/login/loginpb/login.proto",
  options: {
    includeDirs: ["proto"],
  },
  packageName: "loginpb",
  serviceName: "LoginService",
  rules: []
});

mockServer.listen("0.0.0.0:50051");