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

TypeError: Cannot read property 'length' of undefined #739

Closed
avokhmin opened this issue Sep 12, 2019 · 12 comments
Closed

TypeError: Cannot read property 'length' of undefined #739

avokhmin opened this issue Sep 12, 2019 · 12 comments
Assignees
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub API. priority: p2 Moderately-important priority. Fix may not be included in next release. status: duplicate Duplicate. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@avokhmin
Copy link

avokhmin commented Sep 12, 2019

Environment details

  • OS: Google Cloud Functions
  • Node.js version: 8
  • npm version:
  • @google-cloud/pubsub version: 0.32.0

Steps to reproduce

const pubsub = new PubSub();
const data = JSON.stringify({ id: `foo`, operation: { name: `bar` } });
const dataBuffer = Buffer.from(data);
pubsub.topic(`projects/project-id/topics/xxx`).publish(dataBuffer).then(messageId => {
  console.log(`Message ${messageId} published.`);
  callback();
}).catch(err => {
  console.error('ERROR:', err);
  callback();
});

and error:

{
 insertId:  "000000-bd28418c-a3e9-4001-beca-235601190e6d"   
 receiveTimestamp:  "2019-09-12T14:35:01.511527849Z"   
 severity:  "ERROR"   
 textPayload:  "ERROR: TypeError: Cannot read property 'length' of undefined
    at Root.load (/srv/node_modules/protobufjs/src/root.js:192:44)
    at Root.loadSync (/srv/node_modules/protobufjs/src/root.js:235:17)
    at Object.loadSync (/srv/node_modules/@grpc/proto-loader/build/src/index.js:230:27)
    at GrpcClient.loadFromProto (/srv/node_modules/google-gax/build/src/grpc.js:118:44)
    at GrpcClient.loadProto (/srv/node_modules/google-gax/build/src/grpc.js:145:21)
    at new PublisherClient (/srv/node_modules/@google-cloud/pubsub/build/src/v1/publisher_client.js:121:28)
    at PubSub.getClientAsync_ (/srv/node_modules/@google-cloud/pubsub/build/src/pubsub.js:633:25)
    at <anonymous>"   
 timestamp:  "2019-09-12T14:35:00.812Z"   
}

With 0.31.1 all works good.

@callmehiphop callmehiphop added priority: p2 Moderately-important priority. Fix may not be included in next release. status: duplicate Duplicate. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Sep 12, 2019
@callmehiphop
Copy link
Contributor

👋 @avokhmin thanks for reporting this! We've actually been seeing the same issue in a few of our other clients (googleapis/nodejs-text-to-speech#266, googleapis/nodejs-scheduler#131).

@alexander-fenster just an FYI

@alexander-fenster
Copy link
Contributor

Yeah, seems like there is some weird usecase where undefined gets all the way down to protobufjs. I'm trying to understand what's going on.

@avokhmin Can I bother you installing the version of this library with some extra logging and pasting the output here? Just do

npm install googleapis/nodejs-pubsub#debug

(it will install the library right from my GitHub branch)

Thank you for helping us fix it!

@pphetra
Copy link

pphetra commented Sep 13, 2019

I have the same problem. Here is console log after install googleapis/nodejs-pubsub#debug.

=== Debug information ===
opts: {"credentials":{-----not shown here----,"projectId":"xxxxxx"}
global.isBrowser: undefined
nodejsProtoPath: /Users/pphetra/projects/horizon/new-horizons-server/functions/node_modules/@google-cloud/pubsub/build/protos/protos.json
opts.fallback: undefined
loadProto arg: /Users/pphetra/projects/horizon/new-horizons-server/functions/node_modules/@google-cloud/pubsub/build/protos/protos.json
 === End of debug information ===
/Users/pphetra/projects/horizon/new-horizons-server/functions/node_modules/protobufjs/src/root.js:193
    for (var i = 0, resolved; i < filename.length; ++i)
                                           ^
TypeError: Cannot read property 'length' of undefined
    at Root.load (/Users/pphetra/projects/horizon/new-horizons-server/functions/node_modules/protobufjs/src/root.js:192:44)
    at Root.loadSync (/Users/pphetra/projects/horizon/new-horizons-server/functions/node_modules/protobufjs/src/root.js:235:17)
    at Object.loadSync (/Users/pphetra/projects/horizon/new-horizons-server/functions/node_modules/@grpc/proto-loader/build/src/index.js:230:27)
    at GrpcClient.loadFromProto (/Users/pphetra/projects/horizon/new-horizons-server/functions/node_modules/google-gax/build/src/grpc.js:118:44)
    at GrpcClient.loadProto (/Users/pphetra/projects/horizon/new-horizons-server/functions/node_modules/google-gax/build/src/grpc.js:145:21)
    at new PublisherClient (/Users/pphetra/projects/horizon/new-horizons-server/functions/node_modules/@google-cloud/pubsub/build/src/v1/publisher_client.js:133:28)
    at Object.<anonymous> (/Users/pphetra/projects/horizon/new-horizons-server/functions/x.js:2:13)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)```

@jpreynat
Copy link

Same problem here using @google-cloud/[email protected]

@Draiken
Copy link

Draiken commented Sep 13, 2019

Seems to be an issue with using an older version of gax-nodejs.
Old gax versions don't allow loadProto to be used with a single parameter, passing undefined down to loadFromProto

googleapis/gax-nodejs@e570cfa

Either PubSub needs to use the older version properly or update gax

@alexander-fenster
Copy link
Contributor

@Draiken That's a great (and possible) explanation to why undefined gets there! PubSub depends on "google-gax": "^1.0.0" which must pull the latest 1.x version (and the change to allow single parameter got released in google-gax v1.2.0), but if you have a lockfile, it might explain everything.

To all folks affected by the issue: can you please make your code do npm ls and send the output here? Removing your package-lock.json and node_modules and reinstalling should also help then.

But why not - let me send a PR to bump the gax dependency to the latest one and we'll see if it helps you folks. Here we go: #740

@alexander-fenster
Copy link
Contributor

Can you folks try installing @google-cloud/pubsub v0.32.1, double check that it pulled google-gax v1.5.2+, and let us know here if the problem is still there?

Thank you!

@avokhmin
Copy link
Author

Can you folks try installing @google-cloud/pubsub v0.32.1, double check that it pulled google-gax v1.5.2+, and let us know here if the problem is still there?

Thanks, v0.32.1 works good for me 👍 🙇

@Draiken
Copy link

Draiken commented Sep 16, 2019

This fixed the issue for me too. Thanks

@callmehiphop
Copy link
Contributor

@Draiken awesome, thanks for stopping by to let us know!

@amitized
Copy link

I was facing this issue when trying to run my script on Google sheets. Is this a similar issue? mithunmanohar/woocommerce-orders-google-sheets-integration#44

@abdullahmujahidali
Copy link

Having the same issue, I have double-checked everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub API. priority: p2 Moderately-important priority. Fix may not be included in next release. status: duplicate Duplicate. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

8 participants