I am trying to have a Go application and Node backend communicated via gRPC. But I am facing some issues with the google-protobuf lib when trying to unit-test the code. The issue seems that when running jest is not able to import google-protobuf for some reason (the app is working fine just no unit test can pass anymore).
node: v16.19.0
google-protobuf: v3.21.2
The error:
ReferenceError: self is not defined
at Object.self (../../../node_modules/google-protobuf/google-protobuf.js:12:314)
The generated protos looks like that:
var jspb = require('google-protobuf');
var goog = jspb;
var global = Function('return this')();
var google_api_annotations_pb = require('../../../../google/api/annotations_pb.js');
goog.object.extend(proto, google_api_annotations_pb);
var google_protobuf_field_mask_pb = require('google-protobuf/google/protobuf/field_mask_pb.js');
goog.object.extend(proto, google_protobuf_field_mask_pb);
var google_protobuf_timestamp_pb = require('google-protobuf/google/protobuf/timestamp_pb.js');
It calls var jspb = require('google-protobuf'); as expected by the import, seems to get stuck at this point.
I am trying to have a Go application and Node backend communicated via gRPC. But I am facing some issues with the
google-protobuf
lib when trying to unit-test the code. The issue seems that when runningjest
is not able to importgoogle-protobuf
for some reason (the app is working fine just no unit test can pass anymore).node: v16.19.0 google-protobuf: v3.21.2
The error:
The generated protos looks like that:
It calls
var jspb = require('google-protobuf');
as expected by the import, seems to get stuck at this point.where this and self are not defined