Node.js at Google Cloud Platform Pub / Sub tutorial works with "TypeError: cannot call method 'on' of null"

I am getting an error while running https://cloud.google.com/nodejs/getting-started/using-pub-sub . (I have successfully completed the previous tutorials in the series.)

With the command "SCRIPT = worker.js PORT = 8081 npm start", I get this error related to background.js:

TypeError: Cannot call method 'on' of null
    at /Users/xke/Documents/node.js/6-pubsub/lib/background.js:57:20
    at /Users/xke/Documents/node.js/6-pubsub/node_modules/gcloud/lib/pubsub/index.js:256:7
    at /Users/xke/Documents/node.js/6-pubsub/node_modules/gcloud/lib/common/util.js:684:11
    at Object.handleResp (/Users/xke/Documents/node.js/6-pubsub/node_modules/gcloud/lib/common/util.js:192:5)
    at Request._callback (/Users/xke/Documents/node.js/6-pubsub/node_modules/gcloud/lib/common/util.js:679:12)
    at Request.self.callback (/Users/xke/Documents/node.js/6-pubsub/node_modules/request/request.js:354:22)
    at Request.EventEmitter.emit (events.js:98:17)
    at Request.<anonymous> (/Users/xke/Documents/node.js/6-pubsub/node_modules/request/request.js:1207:14)
    at Request.EventEmitter.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/Users/xke/Documents/node.js/6-pubsub/node_modules/request/request.js:1153:12)

      

Thoughts / decisions?

Thank!

+3


source to share


1 answer


It seems to be a bug in the gcloud-node library . The library is supposed to automatically create the theme for you, but it seems like there is an edge case where the theme is not automatically generated when you try to subscribe to it.

In the meantime, there is an easy way: launch the bookshelf app and create / edit a book. This will force the library to create a theme. This is because the library correctly automatically creates a theme when trying to publish it. After that, you should be able to start the worker without errors.



Alternatively, you can modify background.js@subscribe

to check for the existence of the topic and create it if necessary.

+1


source







All Articles