When i am trying to switch to new grpc package (@grpc/grpc-js)from existing package(grpc) in my existing code i am getting the error
code
const grpc = require("@grpc/grpc-js");
const protoLoader = require("@grpc/proto-loader");
const confiq = require('confiq').default;
const PROTO_PATH = __dirname + '/proto';
const { url, port } = confiq('style')
const packageDefinition = protoLoader.loadSync(
`${PROTO_PATH}/style.proto`,
{
longs: Number,
enums: String,
defaults: true,
oneofs: true,
includeDirs:
[
PROTO_PATH
]
});
const SERVICE_URL = `${url}:${port}`
const StyleProto = grpc.loadPackageDefinition(packageDefinition).com.xxx.style;
const grpcCredentials = grpc.credentials.createInsecure();
function call(method, requestData) {
const clientStub = new StyleProto.StyleService(SERVICE_URL, grpcCredentials, {
'grpc.max_send_message_length': 10485760,
'grpc.max_receive_message_length': 629145600
});
if (!clientStub[method])
throw new Error('Method not available');
return new Promise((resolve, reject) => {
clientStub[method](requestData, (err, data) => {
console.log(err)
console.log(data)
if (err || data.statusResponse.statusType === 'ERROR')
reject(err || data);
resolve(data);
});
});
}
module.exports = call;
ERROR
at callErrorFromStatus (xxx/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
at Object.onReceiveStatus (xxx/node_modules/@grpc/grpc-js/build/src/client.js:180:80)
at Object.onReceiveStatus (xxx/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
at Object.onReceiveStatus (xxx/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
at xxx/node_modules/@grpc/grpc-js/build/src/resolving-call.js:94:78
at processTicksAndRejections (internal/process/task_queues.js:77:11)
for call at
at ServiceClientImpl.makeUnaryRequest xxx/style-service-client/node_modules/@grpc/grpc-js/build/src/client.js:160:32)
at ServiceClientImpl.<anonymous> xxx/style-service-client/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
at Object.<anonymous> xxx/style-service-client/src/adsTest.js:29:12)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47 {
code: 13,
details: 'No message received',
metadata: Metadata { internalRepr: Map(0) {}, options: {} }
}
If i change back the first line back to const grpc = require('grpc') it starts working again
As much as i know the packages are supposed to be compatible with each other, not sure if i am missing anything here
Package version
"@grpc/grpc-js": "^1.8.18",
"@grpc/proto-loader": "^0.7.8",
"async": "^3.2.4",
"confiq": "0.0.3",
"grpc": "^1.24.11",
"lodash": "^4.17.21"
Node version v14.20.1