mtoninelli
mtoninelli

Reputation: 714

google-protobuf - Can't find variable: proto

I got an issue using google-protobuf (v3.21.0) in React Native (v0.65.1) in order to connect device (IoT) via SoftWiFi using expressif (Security1)

After creating succesfully the private and public keys with the curve25519 I need to use protobuf for passing the payload. To do so, I'm following this explanation: https://medium.com/@singhandresh09/using-protobuf-in-react-native-7cc8286389f5

After have created successfully the js files with the protoc compiler I lunch successfully the app.

The error I got refers to the file created by protoc session_pb.js:

Can't find variable: proto

goog.object.extend(proto, sec0_pb)

To replicate it here is what I do.

and then used it

   const s = new session_pb.S0SessionCmd();
   const r = s.setClientPubKey('123');

I've noticed that in the created js files the "proto" is not defined anywhere. Here the file generated:

...
// GENERATED CODE -- DO NOT EDIT!
/* eslint-disable */
// @ts-nocheck

var jspb = require('google-protobuf');
var goog = jspb;
var global = (function() { return this || window || global || self || Function('return this')(); }).call(null);

var sec0_pb = require('./sec0_pb.js');
goog.object.extend(proto, sec0_pb);   <--- here is where the error occurs
var sec1_pb = require('./sec1_pb.js');
goog.object.extend(proto, sec1_pb);
var sec2_pb = require('./sec2_pb.js');
goog.object.extend(proto, sec2_pb);
...

enter image description here

Upvotes: 1

Views: 502

Answers (1)

Shun  Kashiwa
Shun Kashiwa

Reputation: 11

I encountered the same issue and resolved it by disabling the inlineRequires in metro.config.js.

{
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  }
}

Upvotes: 1

Related Questions