Skip to content

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

Closed
@xNok

Description

@xNok

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions