Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail to load google-protobuf in node environnement (unit test with jest) #160

Closed
xNok opened this issue Dec 22, 2022 · 1 comment
Closed

Comments

@xNok
Copy link

xNok commented Dec 22, 2022

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.

goog.global=this||self

where this and self are not defined

@xNok xNok changed the title fail to load google-protobuf in node environnement fail to load google-protobuf in node environnement (unit test with jest) Jan 3, 2023
@dibenede
Copy link
Contributor

dibenede commented Jan 3, 2023

Thanks for reporting this. We are aware of this issue; closing as a dupe of #149 .

@dibenede dibenede closed this as completed Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants