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.

TypeError: Cannot read property 'publish' of undefined

See original GitHub issue

while running my producer.js I get the following error -> command : node stomjs/producer.js response: /home/dibyajyoti/Desktop/Feed/node_modules/@stomp/stompjs/bundles/stomp.umd.js:506 this._stompHandler.publish(params); ^

TypeError: Cannot read property ‘publish’ of #undefined at Client…/src/client.ts.Client.publish (/home/dibyajyoti/Desktop/Feed/node_modules/@stomp/stompjs/bundles/stomp.umd.js:506:28) at Object.<anonymous> (/home/dibyajyoti/Desktop/Feed/stomjs/producer.js:43:8) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions…js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad #(internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Function.Module.runMain (internal/modules/cjs/loader.js:742:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

I’m using it with activemq, it’s getting connected but throwing error while sending a message! my stomp configuration is:

`global.WebSocket = require(“ws”);

const Stomp = require(“@stomp/stompjs”);

if (typeof TextEncoder !== “function”) { const TextEncodingPolyfill = require(“util”); TextEncoder = TextEncodingPolyfill.TextEncoder; TextDecoder = TextEncodingPolyfill.TextDecoder; }

const stompConfig = { brokerURL: “ws://localhost:61614/ws”, connectHeaders: { login: “username”, passcode: “password” }, debug: function(message) { console.log(message); }, onWebSocketClose: function(message) { console.log("Reason: ", message.reason); }, onWebSocketError: function() { console.log(“Web socket error”); }, onConnect: function(frame) { console.log(“Client connected to”, frame.headers.server); }, onDisconnect: function() { console.log(“Client disconnected”); }, onStompError: function(frame) { console.log("Broker reported error: " + frame.headers[“message”]); console.log("Additional details: " + frame.body); }, reconnectDelay: 5000, heartbeatIncoming: 4000, heartbeatOutgoing: 4000 };

const client = new Stomp.Client(stompConfig); client.activate(); client.publish({ destination: “/queue/test”, headers: { priority: 9 }, body: “Hello, STOMP” });`

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kum-deepakcommented, May 6, 2019

There is a delay between calling client.activate and the actual connection getting established. You have two options:

  • Write your code inside onConnect. However, onConnect gets called every time a connection is established (like a reconnect after an error).
  • Check for Client#connected before calling publish.

There is wrapper of this library - https://github.com/stomp-js/rx-stomp - that uses rxjs. That wrapper supports local queuing of messages if the underlying connection is not there.

0reactions
dibyajyotironcommented, May 10, 2019

Thanks for the replies, for now I’ve switched to node-stomp and it’s working fine for my usage. For my application requirement, stomp-js is not serving my purpose!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'publish' of undefined in ...
1 Answer 1 · So remove the declaration in the const? – Ron Arel. May 23, 2018 at 4:11 · Juat to clarify....
Read more >
TypeError: Cannot read property 'publish' of undefined - ionic-v3
Hi, every time this throwErrorObservable is called i get undefined error (due to the events objects which is undefined) I cannot understand ...
Read more >
Error while publishing: Cannot read properties of undefined ...
Hi,. I just merged from Azure DevOps a pull request. This pull request contains some changes to an existing (huge) dataflow.
Read more >
Lightning Component Error: TypeError: Cannot read property ...
[There was an error rendering a Skuid Page component for page DHC_Physician_Search. TypeError: Cannot read property 'publish' of undefined].
Read more >
TypeError: Cannot read properties of undefined (reading 'page')
Hello, when i want to publish an article, an error occurs again: TypeError: Cannot read properties of undefined (reading 'page') at…
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