question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

webpack on the browser "cannot read property 'status' of undefined"

See original GitHub issue

References:

http://5.9.10.113/67017244/google-cloud-pubsub-typeerror-cannot-read-property-status-of-undefined https://github.com/googleapis/nodejs-pubsub/issues/1011 https://github.com/googleapis/gax-nodejs/pull/554

// pull-retry.js

const google_gax_1 = require("google-gax");
/*!
 * retryable grpc.status codes
 */
exports.RETRY_CODES = [
    google_gax_1.grpc.status.DEADLINE_EXCEEDED,
    google_gax_1.grpc.status.RESOURCE_EXHAUSTED,
    google_gax_1.grpc.status.ABORTED,
    google_gax_1.grpc.status.INTERNAL,
    google_gax_1.grpc.status.UNAVAILABLE,
    google_gax_1.grpc.status.CANCELLED,
];

I understand that there isn’t supposed to be support for webpack, but it seems like it shouldn’t be that bad to hack a few libraries into working. I’ve tried the following just to hack past the errors that I’ve seen in browser:

// @google-cloud/pubsub/build/src/pull-retry.js : 20

const google_gax_1 = require("google-gax");
<NEW>
google_gax_1.grpc = {"status": {}};
</NEW>

The above fixes the original error, but then I get another error that I fix below

// google-auth-library/build/src/auth/googleauth.js : 415

resolve("my-project-id");
// child_process_1.exec('gcloud config config-helper --format json', (err, stdout) => {
//     if (!err && stdout) {
//         try {
//             const projectId = JSON.parse(stdout).configuration.properties.core.project;
//             resolve(projectId);
//             return;
//         }
//         catch (e) {
//             // ignore errors
//         }
//     }
//     resolve(null);
// });

I’m currently stuck at @google-cloud/pubsub/build/src/v1/publisher_client.js : 110

const google_gax_1 = require("google-gax");
...
this.iamClient = new google_gax_1.IamClient(this._gaxGrpc, opts);

google_gax_1.IamClient is undefined for some reason and it therefore says that google_gax_1.IamClient is not a constructor.

I this path of hacking through libraries likely to work for me in the end or am I doomed?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
cdelguerciocommented, Jun 25, 2021

Also, for reference my code is almost identical to the example code for Publishing to a topic in Node.

https://cloud.google.com/pubsub/docs/publisher

The only difference being that I authenticate explicitly.

const topicName = 'interaction-input';
const data = JSON.stringify({interaction1: 1, interaction2: 2, interaction3: 3, interaction4: 4});

// Creates a client; cache this for further use
const googleAuth = new GoogleAuth({projectId: "my-project", credentials: {client_email: "my-publish-only-service-account@myapp.iam.gserviceaccount.com", private_key: "my-private-key"}});
const clientConfig = {auth: googleAuth};
const pubSubClient = new PubSub(clientConfig);

async function publishMessage() {
  // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject)
  const dataBuffer = Buffer.from(data);

  const messageId = await pubSubClient.topic(topicName).publish(dataBuffer);
  console.log(`Message ${messageId} published.`);
  console.log(data);
}

publishMessage().then(() => {
  done();
}).catch(error => {
  console.error(`Received error while publishing: ${error.message}`);
  throw(error);
});
0reactions
feywindcommented, Aug 16, 2022

The latest feedback I’ve gotten re: using the library in a browser context is that we really don’t support that at this point, but it’s something that we’re periodically revisiting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack: TypeError: Cannot read property ... - Stack Overflow
Webpack: TypeError: Cannot read property 'properties' of undefined · it works fine for me, can you clarify which script gives the error? What ......
Read more >
typeerror: cannot read property 'descendant' of undefined
That is, the primary problem being: TypeError: Cannot read property 'properties' of undefined. The best solution I've found to the problem is to...
Read more >
TypeError: Cannot read property 'data' of undefined
catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/ ...
Read more >
Cannot Read Property Length of Undefined in JavaScript
The TypeError: Cannot read property 'length' of undefined is one of the most common type errors in JavaScript. It occurs when the length ......
Read more >
ERROR TypeError: Cannot read property title of undefined
HEY, SET YOUR LIKE THERE ! ... Your browser can't play this video. ... Solved: ERROR TypeError: Cannot read property title of undefined....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found