ng2-mqtt icon indicating copy to clipboard operation
ng2-mqtt copied to clipboard

ReferenceError: window is not defined

Open xmachupicchux opened this issue 7 years ago • 3 comments

Hello, I am using Angular 4 CLI + Universal and I am getting always following error:

/Users/Picchu/Documents/em/node_modules/ng2-mqtt/mqttws31.js:2143
})(window);
ReferenceError: window is not defined
    at Object.<anonymous> (/Users/Picchu/Documents/em/node_modules/ng2-mqtt/mqttws31.js:2143:4)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.defineProperty.value (/Users/Picchu/Documents/em/dist/server.js:6948:18)
    at __webpack_require__ (/Users/Picchu/Documents/em/dist/server.js:20:30)

How can I fix this?

xmachupicchux avatar Oct 18 '17 08:10 xmachupicchux

I don't think that the js lib that is used in this project (mqttws31) is supported in cli mode. The lib would need to be rewritten to take this into account, since its currently using setTimeout to schedule the pinger.

icanos avatar Oct 18 '17 11:10 icanos

Ok and how I should do this? Within your lib or in my Angular component? The problem occurs on server side. I am using Node.js with Angular CLI + Universal

xmachupicchux avatar Oct 20 '17 13:10 xmachupicchux

This is part of the Paho mqttws31 lib and its there that the change needs to happen.

icanos avatar Mar 25 '19 14:03 icanos