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: __webpack_require__.g.ActiveXObject is not a constructor

See original GitHub issue

I use centrifuge to connect to DonationAlerts server and everything works fine until I get to 3rd step where Centrifuge has to send POST ajax request to DA endpoint in order to get channel subscription token.

This is my code:

centrifuge.subscribe('$alerts:donation_235774', function(message) {
    console.log('new message', message)
});

And I get error:

TypeError: __webpack_require__.g.ActiveXObject is not a constructor
    at Centrifuge._ajax (/fakepath/node_modules/centrifuge/dist/centrifuge.js:193:101)
    at Centrifuge.stopSubscribeBatching (/fakepath/node_modules/centrifuge/dist/centrifuge.js:2329:24)
    at Centrifuge._subscribe (/fakepath/node_modules/centrifuge/dist/centrifuge.js:1392:16)
    at Subscription.subscribe (/fakepath/node_modules/centrifuge/dist/centrifuge.js:2786:24)
    at Centrifuge.subscribe (/fakepath/node_modules/centrifuge/dist/centrifuge.js:2351:11)
    at subscribeToDonations (/fakepath/cen.js:27:14)
    at Centrifuge.<anonymous> (/fakepath/cen.js:20:3)
    at Centrifuge.emit (/fakepath/node_modules/centrifuge/dist/centrifuge.js:3089:5)
    at Centrifuge._connectResponse (/fakepath/node_modules/centrifuge/dist/centrifuge.js:1550:12)

Looks like it only happens when channel name starts with $ character. I tried alerts:donation_235774, news — no errors. But as soon as I add $ before anything — it breaks. Also tried aasd$asdas and no errors thrown.

OS: MacOS Big Sur 11.0.1 Version of Centrifuge-js: 2.7.5 NodeJS version: v15.2.1 NPM version: 7.0.10 I use WebSockets for nodejs, also tried with sockjs and it couldn’t even connect to server

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
FZambiacommented, May 28, 2021

Cool, looks like we need to add explicit option to pass it into Centrifuge like we have with WebSocket and mention in readme.

0reactions
VityaSchelcommented, May 28, 2021

Hello, try to add https://www.npmjs.com/package/xmlhttprequest to dependencies of your NodeJS project and then:

const Centrifuge = require('centrifuge');

global.WebSocket = require('ws'); 
global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

var centrifuge = new Centrifuge('ws://localhost:8000/connection/websocket')

Thanks! Works perfect

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack imported module is not a constructor - Stack Overflow
For me, this error was caused by importing through index files. I had multiple directories with their index.ts files that exported all the...
Read more >
TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >
59.94% (199 / 332) Functions: 86.49% (333 / 385) Lines
toEqual(true); }); // TODO Blob is not a constructor in PhantomJS // it('should validate Blob', function () { // expect(utils.isBlob(new Blob())).
Read more >
webpack/webpack - Gitter
Hi everyone, I'm trying to move my old amd module based library to esm & also from grunt to webpack. I'm using this...
Read more >
JavaScript Error Handling - X Is Not a Constructor TypeError
A deep dive into the X Is Not a Constructor TypeError within JavaScript, including a quick overview of constructors with simple code ...
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